Hi Rashid,
fn:tokenize on an empty string is probably not the best idea, as the
regex of an empty string matches things you probably don't mean for it
to match (for example, the it matches the empty string at the beginning
of the string). Also, in the latest version of the XQuery spec, it will
raise an error.
To find the second one of the sequence returned by fn:index-of, you can
just use a positional predicate.
Here are two ways you might accomplish this, one using
string-to-codepoints and one generating a sequence of characters that
make up the string:
fn:index-of(fn:string-to-codepoints("a large land is big in area"),
fn:string-to-codepoints("a"))[2]
let $characters :=
let $string := "a large land is big in area"
for $char at $index in 1 to fn:string-length($string)
return fn:substring($string, $char, 1)
return
fn:index-of($characters, "a")[2]
Both of these return 4, which is the position of the second "a" in the
string. The string-to-codepoints one is likely more efficient.
Hope this helps,
-Danny
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Nizamuddin, Rashid
Sent: Wednesday, October 31, 2007 1:18 PM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] Index function in xquery
I think I asked this question long time back and forgot again.
Could anyone please tell me how to get the index of second occurrence of
a specific character in the string
index-of(tokenize("a large land is big in area", ""), "a")
This will give all the index position of a. I need the index of second
position. Or is this something I have to loop through and exit the loop
when the counter is 2.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Griffin,
Matt
Sent: Thursday, May 17, 2007 10:54 AM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] Index function in xquery
index-of(tokenize("a large land is big in area", ""), "a")
will produce a sequence containing all of index of every "a"
-Matt
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Nizamuddin, Rashid
Sent: Thursday, May 17, 2007 1:47 PM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] Index function in xquery
Is there an indexof function in xquery which returns the index of the
the occurring match I wanted to know the second occurrence for "a" in
the following word
"a large land is big in area"
I need to find out the index or the integer value of the second
occurrence of a.
Any advice
Rashid
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general