find in string

  • Thread starter Bite My Bubbles
  • Start date
B

Bite My Bubbles

How can i count the number of times a string appears within another string.
Thanks a
lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
 
E

Evertjan.

Manohar Kamath [MVP] wrote on 09 aug 2003 in
microsoft.public.inetserver.asp.general:
Dim arElem
Dim myString
Dim mySubString

myString = "this contains the word how many times just one time"
mySubString = "how many times"
arElem = Split(myString, mySubString)

Response.Write("Number of times: " & UBound(arElem))

The case insensitive way, often used by me:

MyNum = UBound(Split(ucase(myString), ucase(mySubString)))
Response.Write "Number of times: " & myNum

This also does not keep a large array in memory, (I hope).
 
B

Bite My Bubbles

that;s a good one thanks
Manohar Kamath said:
One way to do this is kinda a round about way. Use the Split function to
split the string into an array, and count the number of array elements,
minus one.

Dim arElem
Dim myString
Dim mySubString

myString = "this contains the word how many times just one time"
mySubString = "how many times"
arElem = Split(myString, mySubString)

Response.Write("Number of times: " & UBound(arElem))

You could also use the InStr function, and loop through the first ring to
count number of times the string appears.

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com



lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
B

Bite My Bubbles

that's a good one too!

Evertjan. said:
Manohar Kamath [MVP] wrote on 09 aug 2003 in
microsoft.public.inetserver.asp.general:

The case insensitive way, often used by me:

MyNum = UBound(Split(ucase(myString), ucase(mySubString)))
Response.Write "Number of times: " & myNum

This also does not keep a large array in memory, (I hope).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top