<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;
}
> -----Original Message-----
> From: Ketan Patel [mailto:[EMAIL PROTECTED]
> Sent: dinsdag 20 januari 2004 17:09
> To: CF-RegEx
> Subject: RE: Regex function help needed.
>
> Hi,
> I have CFMX and CF5.0 both. Unfortunately my development
> server is CF5.0 and my production server is CFMX. SO CFMX
> should be fine.
>
> Ketan Patel
>
>
> -----Original Message-----
> From: Pascal Peters [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, January 20, 2004 11:00 AM
> To: CF-RegEx
> Subject: RE: Regex function help needed.
>
>
> What version of CF?
>
> > -----Original Message-----
> > From: Ketan Patel [mailto:[EMAIL PROTECTED]
> > Sent: dinsdag 20 januari 2004 17:02
> > To: CF-RegEx
> > Subject: Regex function help needed.
> >
> > Hi all,
> > I am looking for a regular _expression_ where I can get first
> > 1,2,3 words of teh sentence. I want to pass a prameter saying
> > give me 1, 2 or 3 words of teh sentence.
> >
> > Suppose My sentence is:
> > Hotel Reservations Online. Discount Hotel Reservations in
> > every city - Orlando, Las Vegas, New York, London, Miami and more.
> >
> > I want to get just 1 word then it should be Hotel. If 2 words
> > then it should be Hotel Reservations.
> >
> >
> > Ketan Patel
> >
> >
> >
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
