Click to See Complete Forum and Search --> : Get char occurance count


Pipe
October 11th, 2001, 09:21 AM
Hello-

What is the fastest way to determine if there are more than 1 "*" characters in a string?

Thanks - Pipe

John G Duffy
October 11th, 2001, 09:27 AM
If you are using VB 6.0, the quickest way is to use the Split command with the "*" as the delimiter like so

private Sub Command1_Click()
Dim strString
Dim strArray
strString = "**********"
strArray = Split(strString, "*")
MsgBox UBound(strArray) + 1
End Sub




John G

Cimperiali
October 11th, 2001, 09:35 AM
split function with "*" as delimiter should be quite fast (I think more than instr function in a loop for the len of the string exiting when not found anymore).
You will receive an array with ubound = number of "*" char -1.

Maybe you could do some fancy tricks with binary data and Copymemory Api, but these are not my best way of working...


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Cimperiali
October 11th, 2001, 09:41 AM
Beated in speed by you.
Sorry for my redundance, King.
;-)
Have a nice day, J.G.D.

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater