Number of occurrences in a string

# Thread: Number of occurrences in a string

1. Junior Member
Join Date
Dec 1969
Posts
15

## Number of occurrences in a string

Hey,<BR><BR>I need to find out how many times "," occurrs in a string eg<BR><BR>mystring = "1,2,3,4"<BR><BR>I need to know that there are 3 "," in mystring.<BR><BR>cheers

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## Well...

There are many ways. From that query...<BR><BR>intOccurrances = UBound(Split(mystring, ","))<BR><BR>Craig.

3. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## RE: Number of occurrences in a string

Theres a million ways of doing this, heres one:<BR><BR>&#060;%<BR>textSearch = "1,2,3,4"<BR>CountStr = 0<BR>ScanStr textSearch,",",1<BR>Response.write "Found " & CountStr<BR><BR>Function ScanStr(textSearch,find,LastFound) <BR> FoundAt = InStr(LastFound,textSearch,find) <BR> If FoundAt&#062;0 then <BR> CountStr = CountStr + 1<BR> ScanStr textSearch,find,FoundAt+1<BR> End If <BR>End Function

4. Junior Member
Join Date
Dec 1969
Posts
15

## RE: Well...

ta,<BR><BR>worked a treat,<BR><BR>matt

5. Senior Member
Join Date
Dec 1969
Posts
905

## OT: Matt - check yesterdays thread

You, know the one where you called me a Goon and I said you were acting like a prick. HeHe ;)<BR><BR>I&#039;ve posted an answer, let me know if you&#039;re still not getting it as I will check further down later on.<BR><BR>Matt

6. Senior Member
Join Date
Dec 1969
Posts
484

## regular exp

ression could be used also

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•