Click to See Complete Forum and Search --> : Count character occurances
Jenda
October 3rd, 2001, 08:47 AM
Is there a function or something to count the number of occurances of a specific character in a string?
I can implement it using a loop and InStr(), but a builtin would definitely be quicker.
I'm using VB 6.0.
Thanks, Jenda
Cakkie
October 3rd, 2001, 09:44 AM
I'm affraid there's no such function available in VB... so you will have to do it using Instr.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Jenda
October 3rd, 2001, 11:07 AM
Well what could I expect.
Thanks, Jenda
MKSa
October 3rd, 2001, 11:23 AM
Try the Split function. Ex:private Sub Command1_Click()
Dim sText as string
sText = "abc3456copchj"
MsgBox UBound(Split(sText, "c"))
End Sub
deghost
October 3rd, 2001, 03:40 PM
Funny there is a Replace function but not the function you need...
Dim str as string
Dim len1 as Integer
str = "fds11fdgfdgd343111g"
len1 = len(str)
str = Replace$(str, "1", vbNullString)
MsgBox len1 - len(str)
----------
The @host is everywhere!
----------
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.