Dim ArG As String = "in VB my code was"
Dim BrIntervali As Int
For i = 0 To ArG.Length - 1
If ArG.CharAt(i) = " " Then BrIntervali = BrIntervali + 1
Next
Log(BrIntervali)
Is the next step to divide the string, splitting it at each space?
What if there are two spaces together? Is there an empty (zero length) field between the two spaces?
What about leading and trailing spaces?
Your simplest solution might be Regex.Split:
B4X:
LogStringArray(Regex.Split(" ", "Now is the time"))
LogStringArray(Regex.Split(" ", " for all good men "))
LogStringArray(Regex.Split(" ", "to come to the"))
LogStringArray(Regex.Split(" ", " aid of the party."))
Sub LogStringArray(S() As String)
Log("Split into " & S.Length & " substrings")
For I = 0 To S.Length - 1
Log(I & TAB & """" & S(I) & """")
Next
End Sub
First of all, thank you very much for your answers.
I did it like this after searching the forum...
my example:
Sub interval(mstr As String) As Int
Dim pattern As String
pattern = " "
Dim Matcher1 As Matcher
Dim i As Int
i=0
Matcher1 = Regex.Matcher(pattern, mstr)
Do While Matcher1.Find
i=i+1
Log("Found: " & i)
Log("----: " & Matcher1.Match)
Loop
Return i
End Sub
Sub interval(mstr As String) As Int
Dim pattern As String
pattern = " "
Dim Matcher1 As Matcher
Dim i As Int
i=0
Matcher1 = Regex.Matcher(pattern, mstr)
Do While Matcher1.Find
i=i+1
Log("Found: " & i)
Log("----: " & Matcher1.Match)
Loop
Return i
End Sub