Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Count number of instances of a text string

Explorer ,
Oct 23, 2006 Oct 23, 2006
This should be easy to do, right? I'm not finding it in my function list. I have find and refind, but maybe there is a function or custom tag that will return the number of instances of a given substring within a larger text string?

Sorry if I am blanking on something terribly obvious.

Thanks,

Chuck
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 23, 2006 Oct 23, 2006
First do a Replace( ) function, replacing the substring with a character that is guaranteed not to be in your string (like a pipe (|)). Then do a ListLen, using that character as the list delimiter.

<CFSET foo = Replace(bigString, subString, "|", "ALL")>
<CFSET count = ListLen(foo, "|")>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 24, 2006 Oct 24, 2006
No CF function, but you can roll your own. I used REFindNoCase in mine, by you could easily make "case-ness" an optional parameter to the function or just use the Finds instead.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 24, 2006 Oct 24, 2006
LATEST
This works along the same lines aas what jdeline posted.

getOccurenceCount()

CR
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources