[xquery-talk] ask about how to find string between another string

G. Ken Holman gkholman at CraneSoftwrights.com
Tue Nov 30 17:02:32 PST 2010


At 2010-11-30 21:52 +0000, Mohamed kharrat wrote:
>Dear all,
>
>i have this function:
>declare function local:Match($X as xs:string*,$Y as xs:string*)
>{
>
>let $count:=tokenize($X, "\s")
>where
>some $l in $count satisfies
>some $tok2 in tokenize($Y, "\s") satisfies
>contains($l,$tok2)
>return true()
>}
>
>it's ok , it return true where $X exist in $Y
>but the problem is: supposing i have:
>$string1='an '
>$string2= 'the xquery is a language for xml'
>
>this function will return  true because 'an' exist in the word 'language'
>but i want to know how to return true only if the word 'an' exit 
>alone , not in other word of $string2
>
>i hope you understand me.
>thank you

Please see the answer to this that I posted for you yesterday morning 
(copied below).  It is the identical question, with identical 
punctuation, only with a different subject line.

. . . . . . . . . Ken


>Date: Mon, 29 Nov 2010 09:31:42 -0500
>To: talk at x-query.com
>From: "G. Ken Holman" <gkholman at cranesoftwrights.com>
>Subject: Re: [xquery-talk] about function
>
>At 2010-11-29 14:19 +0000, Mohamed kharrat wrote:
>>dear all,
>>i have this function:
>>declare function local:Match($X as xs:string*,$Y as xs:string*)
>>{
>>
>>let $count:=tokenize($X, "\s")
>>where
>>some $l in $count satisfies
>>some $tok2 in tokenize($Y, "\s") satisfies
>>contains($l,$tok2)
>>return true()
>>}
>>
>>it's ok , it return true where $X exist in $Y
>>but the problem is: supposing i have:
>>$string1='an '
>>$string2= 'the xquery is a language for xml'
>>
>>this function will return  true because 'an' exist in the word 'language'
>>but i want to know how to return true only if the word 'an' exit 
>>alone , not in other word of $string2
>>
>>i hope you understand me.
>
>This question was answered for you on November 11 by me and by others.
>
>Don't use "contains()" and you won't have a problem.
>
>The following function will return true() if any 
>non-white-space-string of text in $X is equal to a 
>non-white-space-string of text in $Y:
>
>declare function local:Match($X as xs:string*,$Y as xs:string*)
>{ tokenize($X,'\s') = tokenize($Y,'\s') };
>
>What has changed in your requirement when you asked this question last week?
>
>I hope the example below helps.
>
>. . . . . . . . . Ken
>
>T:\ftemp>type kharrat.xq
>declare function local:Match($X as xs:string*,$Y as xs:string*)
>{ tokenize($X,'\s') = tokenize($Y,'\s') };
>
>local:Match( 'an','the xquery is a language for xml' ),
>local:Match( 'a','the xquery is a language for xml' )
>
>T:\ftemp>xquery kharrat.xq
><?xml version="1.0" encoding="UTF-8"?>false true
>T:\ftemp>


--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:gkholman at CraneSoftwrights.com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



More information about the talk mailing list