Subname: StringCount
Description: I just came across this while searching for something else, I thought it was worth sharing. Count the number of sub strings in a string. This will also give a character count for a single character TargetStr.
Usage:
Tags: Count characters strings b4a b4j b4i
Description: I just came across this while searching for something else, I thought it was worth sharing. Count the number of sub strings in a string. This will also give a character count for a single character TargetStr.
B4X:
Sub StringCount(StringToSearch As String,TargetStr As String,IgnoreCase As Boolean) As Int
If IgnoreCase Then
StringToSearch = StringToSearch.ToLowerCase
TargetStr = TargetStr.ToLowerCase
End If
Return (StringToSearch.Length - StringToSearch.Replace(TargetStr,"").Length) / TargetStr.Length
End Sub
Usage:
B4X:
Dim Test1 As String = "Test to Count the characters in this test string"
Log(StringCount(Test1,"test",True))
Tags: Count characters strings b4a b4j b4i
Last edited: