Hello,
What is a quick way of finding the frequency of a character in a string?
e.g. the number of the letter g in this string “What is a quick way of finding the frequency of a character in a string?”
Thanks.
Lennox
Hello,
What is a quick way of finding the frequency of a character in a string?
e.g. the number of the letter g in this string “What is a quick way of finding the frequency of a character in a string?”
Thanks.
Lennox
Split.
Using the new framework (untested)
Function CountOf(extends t as Text, other as Text) As Integer
dim count as Integer
dim pos as Integer = t.IndexOf(other)
if pos > -1 then
count = count+1
pos = pos + 1
while t.IndexOf(pos,other) > -1
count = count + 1
pos = t.IndexOf(pos,other) + 1
wend
end if
Return count
End Function
Sorry, I said Split, but I should have said CountFields. You won’t find faster.
dim count as integer = s.CountFields( "g" ) - 1