That is true.

But this is a CFMX-only solution. (Which is what he did specify, although he later was suprised it didn't work on 5.0)

He also seemed confused by the [:space:] class, which included more than just the chr(32) character.

If he wanted to correctly capture the words with the non-space word seperators, I would have used a regex instead of the listgetat function.

But I was reading into his purpose. It seems like he wants to compare the string with another version of the string. In that case, I thought simplifying the potential  non-words   would actually help, rather than hurt. Replacing all tabs, line feeds, etc with spaces would (in html) look the same, but the comparison would be more likely to match.

Egads, that's too much info.

Jerry Johnson

>>> [EMAIL PROTECTED] 01/21/04 03:08AM >>>
This does approximately the same as the regexp, but not quite. This will
only work if the space is there as a delimiter (and not a tab or a comma
without a space). If you add delimiters to the listGetAt, you don't put
the sentence correctly together. However, it will work in most cases.
Both our solutions have a problem if the sentence has two words and you
ask for three. In the list solution, just make sure that the
numberOfWords is less then ListLen(sentence," "). For the regexp try

Regexp = "(\w+\W+){0," & (i-1) & "}" & Regexp

> -----Original Message-----
> From: Jerry Johnson [mailto:[EMAIL PROTECTED]
> Sent: dinsdag 20 januari 2004 18:02
> To: CF-RegEx
> Subject: RE: Regex function help needed.
>
> Without Regex.
>
> <cfscript>
> function getwords(sentence,numberOfWords) { var str=""; for
> (i=1;i LTE numberOfWords;i=i+1) {
> str=listAppend(str,listGetAt(sentence,i," ")," ");
> }
> return(str);
> }
> </cfscript>
> <cfset s="Hotel Reservations Online. Discount Hotel
> Reservations in every city -  Orlando, Las Vegas, New York,
> London, Miami and more.">
>
> <cfset fragment=getWords(s,1)>
> <cfoutput>#fragment#</cfoutput><br>
>
> <cfset fragment=getWords(s,2)>
> <cfoutput>#fragment#</cfoutput><br>
> <cfset fragment=getWords(s,3)>
> <cfoutput>#fragment#</cfoutput><br>
> <cfset fragment=getWords(s,4)>
> <cfoutput>#fragment#</cfoutput><br>
> <cfset fragment=getWords(s,5)>
> <cfoutput>#fragment#</cfoutput><br>
>
>
> NOTE: you can replace the " " delimiter in the listGetAt
> function with a list of delimiters if you wish.
>
> Jerry Johnson
>
>
> >>> [EMAIL PROTECTED] 01/20/04 11:40AM >>>
> Then it all depends on what you define as a word.
>
> This should work (NOT TESTED)
>
> function GetWords(string,i){
> var Regexp = "\w+";
> var aTmp = "";
> var out = "";
> if(i GT 1) Regexp = "(\w+\W+){" & (i-1) & "}" & Regexp; aTmp
> = ReFindNoCase(Regexp,string,1,true);
> if(aTmp.pos[1]) out = Mid(string,aTmp.pos[1],aTmp.len[1]);
> return out;
> }
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to