RE: number of occurrences in a string.
It would have to do the search more than twice, it woudl have to do every possible case combination of either the string or the RE. I suspect that internally it just does a LOWER or UPPER on both the RE and the string. -Original Message- From: Philip Arnold [mailto:[EMAIL PROTECTED] Sent: Friday, October 17, 2003 8:15 AM To: CF-Talk Subject: RE: number of occurrences in a string. Wouldn't it be "faster" to use a Lower() on the string rather than REFindNoCase? I thought that doing a NoCase does the search twice, so on long strings, it could be slower... Just a thought [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
\b only on cfmx. As I said before, the array created will give you the number of subexpressions (2: the entire regexp and the subexpr (beg)) of the first match. In cf you need a loop. Try putting 3 beg's in your string. Pascal -Oorspronkelijk bericht- Van: Raymond Camden [mailto:[EMAIL PROTECTED] Verzonden: vr 17/10/2003 17:01 Aan: CF-Talk CC: Onderwerp: RE: number of occurrences in a string. I'm not a regex guru, but what about using the \b boundry: This seems to work well. In a UDF you would just return the arrayLen of foo.pos. Does this seem right to others? _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
I always assumed it said, match A or a, not search twice. I guess it depends on what is happening at the lowest level. I've never seen any recommendations in the past to not use findNoCase or reFindNocase (or etc). [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Wouldn't it be "faster" to use a Lower() on the string rather than REFindNoCase? I thought that doing a NoCase does the search twice, so on long strings, it could be slower... Just a thought -Original Message- From: Raymond Camden [mailto:[EMAIL PROTECTED] Sent: Friday, October 17, 2003 11:02 AM To: CF-Talk Subject: RE: number of occurrences in a string. I'm not a regex guru, but what about using the \b boundry: This seems to work well. In a UDF you would just return the arrayLen of foo.pos. Does this seem right to others? _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Nope, I stand corrected, you still need to loop. But \b may be better than [^a-z]+. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
I'm not a regex guru, but what about using the \b boundry: This seems to work well. In a UDF you would just return the arrayLen of foo.pos. Does this seem right to others? [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
the for loop isn't right: 1. if it doesn't find a match, it continues looping 2. if there is a match, start will become greater than the string length 3. the word is not escaped for special chars in regexp 4. when the new start position is set, it isn't set to the right place (should be +Len(word)+2, but this isn't a problem, it is just not efficient). Look at the code I posted, I think it will be more efficient. Maybe the 4th attribute of REFindNoCase can be dropped and the length to add can be calculated from the original word before escaping. -Oorspronkelijk bericht- Van: Raymond Camden [mailto:[EMAIL PROTECTED] Verzonden: vr 17/10/2003 15:52 Aan: CF-Talk CC: Onderwerp: RE: number of occurrences in a string. What didn't look right about the function? It's working here. _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
What didn't look right about the function? It's working here. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
I was doing _javascript_ when I posted this. Obviously the first element in the array has index 1 in CF. So replace [0] by [1] in my code. -Oorspronkelijk bericht- Van: Pascal Peters Verzonden: vr 17/10/2003 15:08 Aan: CF-Talk CC: Onderwerp: RE: number of occurrences in a string. The function doesn't look correct. This should work (I modified it, but didn't test) function WordInstance(word,string){ var i = 0; var start = 1; var exit = false; var tmp = ""; var special_char_list = "\,+,*,?,.,[,],^,$,(,),{,},|,-"; var esc_special_char_list = "\\,\+,\*,\?,\.,\[,\],\^,\$,\(,\),\{,\},\|,\-"; word = ReplaceList(word, special_char_list, esc_special_char_list); string = " " & string & " "; while(NOT exit){ tmp=REFindNoCase("[^a-z]+#word#[^a-z]+",string,start,true); if(tmp.pos[0] gt 0){ i=i+1; start=tmp.pos[0]+tmp.len[0]; }else{ exit = true; } } return i; } [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
The function doesn't look correct. This should work (I modified it, but didn't test) function WordInstance(word,string){ var i = 0; var start = 1; var exit = false; var tmp = ""; var special_char_list = "\,+,*,?,.,[,],^,$,(,),{,},|,-"; var esc_special_char_list = "\\,\+,\*,\?,\.,\[,\],\^,\$,\(,\),\{,\},\|,\-"; word = ReplaceList(word, special_char_list, esc_special_char_list); string = " " & string & " "; while(NOT exit){ tmp=REFindNoCase("[^a-z]+#word#[^a-z]+",string,start,true); if(tmp.pos[0] gt 0){ i=i+1; start=tmp.pos[0]+tmp.len[0]; }else{ exit = true; } } return i; } Pascal -Oorspronkelijk bericht- Van: Ketan Patel [mailto:[EMAIL PROTECTED] Verzonden: vr 17/10/2003 13:42 Aan: CF-Talk CC: Onderwerp: RE: number of occurrences in a string. Does anybody have answer for this .When I use cflib function wordinstance() sometimes CPU usage will max out ,it reaches its max to 100%. It takes a good amount of time to open the page. This is the only function which give me correct results. My concern is when the site will generate good traffic it will choke the server. I am not sure why. Any help or suggestions are appreciated. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
> What you are returning here is the number if subexpressions of > the first matching word (will always be 2), NOT the wordcount. Damn, yes, you're right. I was thinking perl regex. Sorry! #!/usr/bin/perl $word = "the"; $string = "q giw fieo the nigeow the woeifnw io fmewo the miwo"; @wordarray = $string =~ /[^[:alpha:]]($word)[^[:alpha:]]/g; print scalar(@wordarray) . "\n"; :o\ Tim. --- OUR NEW SITE IS NOW LIVE Visit our new website at http://www.rawnet.com/ and race around the beautiful Bracknell streets at http://xmas.rawnet.com/ --- Tim Blair Web Application Engineer, Rawnet Limited Direct Phone : +44 (0) 1344 393 441 Switchboard : +44 (0) 1344 393 040 --- This message may contain information which is legally privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any unauthorised disclosure, copying, distribution or use of this information is strictly prohibited. Such notification notwithstanding, any comments, opinions, information or conclusions expressed in this message are those of the originator, not of rawnet limited, unless otherwise explicitly and independently indicated by an authorised representative of rawnet limited. --- [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
What you are returning here is the number if subexpressions of the first matching word (will always be 2), NOT the wordcount. To count the number of words, you NEED to loop. Also, you will need to escape the word for regular expressions (escape chars like \$^([ and so on). Finally, you probably want to do a REFindNoCase. Look at CountIt (http://www.cflib.org/udf.cfm?ID=304) on cflib.org, but use REFindNoCase instead of FindNoCase with the regexp in the code. There is an escape function for RegExp on cflib too. Pascal -Oorspronkelijk bericht- Van: Tim Blair [mailto:[EMAIL PROTECTED] Verzonden: vr 17/10/2003 13:59 Aan: CF-Talk CC: Onderwerp: RE: number of occurrences in a string. Try this (watch the wrap): hint="Counts the number of occurences of a given word in a given string"> refind("[^[:alpha:]](#arguments.word#)[^[:alpha:]]", arguments.line, 1, TRUE)> [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
> Will this work in CF5.0 ? *Now* he says... No, it's MX only. But I _think_ this should do it (and work on MX too): function wordcount(word, line) { var wordarray = refind("[^[:alpha:]](#word#)[^[:alpha:]]", line, 1, TRUE)> if (NOT wordarray.len[1]) { return 0; } return arraylen(wordarray.len); } No promises on it working though - only MX here so can't test it. Tim. --- OUR NEW SITE IS NOW LIVE Visit our new website at http://www.rawnet.com/ and race around the beautiful Bracknell streets at http://xmas.rawnet.com/ --- Tim Blair Web Application Engineer, Rawnet Limited Direct Phone : +44 (0) 1344 393 441 Switchboard : +44 (0) 1344 393 040 --- This message may contain information which is legally privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any unauthorised disclosure, copying, distribution or use of this information is strictly prohibited. Such notification notwithstanding, any comments, opinions, information or conclusions expressed in this message are those of the originator, not of rawnet limited, unless otherwise explicitly and independently indicated by an authorised representative of rawnet limited. --- [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Any suggestion for CF5.0 instead of CFMX. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com -Original Message- From: Tim Blair [mailto:[EMAIL PROTECTED] Sent: Friday, October 17, 2003 8:00 AM To: CF-Talk Subject: RE: number of occurrences in a string. > I am looking for which returns the number of occurrences of a word in a > string. It should return the word occurrence count when I pass a word to > search in a string. Try this (watch the wrap): hint="Counts the number of occurences of a given word in a given string"> refind("[^[:alpha:]](#arguments.word#)[^[:alpha:]]", arguments.line, 1, TRUE)> HTH, Tim. --- OUR NEW SITE IS NOW LIVE Visit our new website at http://www.rawnet.com/ and race around the beautiful Bracknell streets at http://xmas.rawnet.com/ --- Tim Blair Web Application Engineer, Rawnet Limited Direct Phone : +44 (0) 1344 393 441 Switchboard : +44 (0) 1344 393 040 --- This message may contain information which is legally privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any unauthorised disclosure, copying, distribution or use of this information is strictly prohibited. Such notification notwithstanding, any comments, opinions, information or conclusions expressed in this message are those of the originator, not of rawnet limited, unless otherwise explicitly and independently indicated by an authorised representative of rawnet limited. --- [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
> Try this (watch the wrap): Oops, replace the output="yes" with output="no" in the cffunction header. Also note that this is a case sensitive search - if you want case insensitive change the refind(...) to refindnocase(...). Tim. --- RAWNET LTD - Internet, New Media and ebusiness Gurus. Visit our new website at http://www.rawnet.com for more information about our company, or call us free anytime on 0800 294 24 24. --- Tim Blair Web Application Engineer, Rawnet Limited Direct Phone : +44 (0) 1344 393 441 Switchboard : +44 (0) 1344 393 040 --- This message may contain information which is legally privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any unauthorised disclosure, copying, distribution or use of this information is strictly prohibited. Such notification notwithstanding, any comments, opinions, information or conclusions expressed in this message are those of the originator, not of rawnet limited, unless otherwise explicitly and independently indicated by an authorised representative of rawnet limited. --- [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
> I am looking for which returns the number of occurrences of a word in a > string. It should return the word occurrence count when I pass a word to > search in a string. Try this (watch the wrap): hint="Counts the number of occurences of a given word in a given string"> refind("[^[:alpha:]](#arguments.word#)[^[:alpha:]]", arguments.line, 1, TRUE)> HTH, Tim. --- OUR NEW SITE IS NOW LIVE Visit our new website at http://www.rawnet.com/ and race around the beautiful Bracknell streets at http://xmas.rawnet.com/ --- Tim Blair Web Application Engineer, Rawnet Limited Direct Phone : +44 (0) 1344 393 441 Switchboard : +44 (0) 1344 393 040 --- This message may contain information which is legally privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any unauthorised disclosure, copying, distribution or use of this information is strictly prohibited. Such notification notwithstanding, any comments, opinions, information or conclusions expressed in this message are those of the originator, not of rawnet limited, unless otherwise explicitly and independently indicated by an authorised representative of rawnet limited. --- [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Does anybody have answer for this .When I use cflib function wordinstance() sometimes CPU usage will max out ,it reaches its max to 100%. It takes a good amount of time to open the page. This is the only function which give me correct results. My concern is when the site will generate good traffic it will choke the server. I am not sure why. Any help or suggestions are appreciated. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com -Original Message- From: Ketan Patel [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 2:21 PM To: CF-Talk Subject: number of occurrences in a string. Hi All, I am looking for which returns the number of occurrences of a word in a string. It should return the word occurrence count when I pass a word to search in a string. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
That's funny, I almost bought Ray the barbie that was previosly listed. -Original Message- From: Robyn Follen [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 2:08 PM To: CF-Talk Subject: RE: number of occurrences in a string. Heh... looked at this and thought... Wow! This guy wants all the same stuff that I want! I suppose that since it WAS my list, it makes a little sense. Looks like this is the link to yours: http://www.amazon.com/exec/obidos/registry/2TCL1D08EZEYE/ref=wl_s_3/103-9347 519-1760600 7519-1760600> ? Pretty short! -robyn [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
This is getting odd, but I noticed the same thing. I went to a blog, noticed the guy had his wish list, and when I clicked on it, I saw mine as well. Is there something special about Amazon wish lists? Sorry for the OT crap folks, I'll try to make up for it with a good blog post later today. :) [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Heh... looked at this and thought... Wow! This guy wants all the same stuff that I want! I suppose that since it WAS my list, it makes a little sense. Looks like this is the link to yours: http://www.amazon.com/exec/obidos/registry/2TCL1D08EZEYE/ref=wl_s_3/103-9347 519-1760600 7519-1760600> ? Pretty short! -robyn -Original Message- From: Raymond Camden [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 2:53 PM To: CF-Talk Subject: RE: number of occurrences in a string. Ahem - without sounding like a total and complete greedy pig, my wish list is here: http://www.amazon.com/exec/obidos/wishlist/ref=cm_wl_topnav_account/002- 3361200-1675257 Feel free to send on over the 500 dollar IPod. (Sorry, can't help asking.) Also I should point out Rob Brooks-Bilson, author of Programming CFMX, is also a big part of the site. (And no one is going to make a crack about how long it takes me to approve UDFs? You folks are too nice.) _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Ahem - without sounding like a total and complete greedy pig, my wish list is here: http://www.amazon.com/exec/obidos/wishlist/ref=cm_wl_topnav_account/002- 3361200-1675257 Feel free to send on over the 500 dollar IPod. (Sorry, can't help asking.) Also I should point out Rob Brooks-Bilson, author of Programming CFMX, is also a big part of the site. (And no one is going to make a crack about how long it takes me to approve UDFs? You folks are too nice.) [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: number of occurrences in a string.
heh...i was just gonna say, "yeah, cflib is great...too bad the owner doesn't have a wish list at Amazon.com so we could repay him in some way" :) (but...just went looking...where *is* your link to the wish list?) charlie - Original Message - From: Raymond Camden To: CF-Talk Sent: Thursday, October 16, 2003 11:34 AM Subject: RE: number of occurrences in a string. Would now be a good time to point out the official CFLIB.org Amazon.com wish list??? -Raymond, who realizes he is WAY behind on the cflib.org queue. > > Check out the following function. Someone on another was > trying to do this yesterday. CFLib.Org has to be one of the > best sites for cool tools. :) > http://www.cflib.org/udf.cfm?ID=304 -Original Message- From: Ketan Patel [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 1:21 PM To: CF-Talk Subject: number of occurrences in a string. Hi All, I am looking for which returns the number of occurrences of a word in a string. It should return the word occurrence count when I pass a word to search in a string. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
It couldn't hurt! :) -Original Message- From: Raymond Camden [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 1:35 PM To: CF-Talk Subject: RE: number of occurrences in a string. Would now be a good time to point out the official CFLIB.org Amazon.com wish list??? -Raymond, who realizes he is WAY behind on the cflib.org queue. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
The cflib function wordinstance() is that sometimes CPU usage will max out , it reaches its max to 100%. I am not sure why. Any help or suggestions are appreciated. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com -Original Message- From: Philip Arnold [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 2:26 PM To: CF-Talk Subject: RE: number of occurrences in a string. http://www.cflib.org/udf.cfm?ID=146 This should do what you want -Original Message- From: Ketan Patel [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 2:21 PM To: CF-Talk Subject: number of occurrences in a string. Hi All, I am looking for which returns the number of occurrences of a word in a string. It should return the word occurrence count when I pass a word to search in a string. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Would now be a good time to point out the official CFLIB.org Amazon.com wish list??? -Raymond, who realizes he is WAY behind on the cflib.org queue. > > Check out the following function. Someone on another was > trying to do this yesterday. CFLib.Org has to be one of the > best sites for cool tools. :) > http://www.cflib.org/udf.cfm?ID=304 -Original Message- From: Ketan Patel [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 1:21 PM To: CF-Talk Subject: number of occurrences in a string. Hi All, I am looking for which returns the number of occurrences of a word in a string. It should return the word occurrence count when I pass a word to search in a string. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
http://www.cflib.org/udf.cfm?ID=146 This should do what you want -Original Message- From: Ketan Patel [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 2:21 PM To: CF-Talk Subject: number of occurrences in a string. Hi All, I am looking for which returns the number of occurrences of a word in a string. It should return the word occurrence count when I pass a word to search in a string. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: number of occurrences in a string.
Check out the following function. Someone on another was trying to do this yesterday. CFLib.Org has to be one of the best sites for cool tools. :) http://www.cflib.org/udf.cfm?ID=304 -Original Message- From: Ketan Patel [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2003 1:21 PM To: CF-Talk Subject: number of occurrences in a string. Hi All, I am looking for which returns the number of occurrences of a word in a string. It should return the word occurrence count when I pass a word to search in a string. Ketan Patel G3 Technology Group, LLC Graphics III Advertising, Inc. (410)789-7007 or (800)783-1799 "It's Not Creative if it doesn't Sell." http://www.g3group.com [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]