Android Question How can i count number of extra dots

Makumbi

Well-Known Member
Licensed User
Please help how can i count number of dots i have in my email please help

B4X:
Dim arrName() As String=Regex.Split(".",Name)
    Log($"Number of commas: ${arrName.Length-1}"$)
    
    If arrName.Length-1 >1 Then
        MsgboxAsync("You have more than one dot in our Email please remove it thanks","More Dots Detected")
        Return
    End If
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have not tested this, but it should count the number of "." characters in a string ...

B4X:
Sub countDots(text As String) As Int
    Dim n As Int = 0
    Dim p As Int = text.IndexOf(".")
    Do While (p > -1)
        n = n + 1
        text = text.SubString(p + 1)
        p = text.IndexOf(".")
    Loop
    Return n
End Sub
 
Last edited:
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Maybe:

B4X:
    If arrName.Length - arrName.Replace(".", "").Length > 1 Then
        MsgboxAsync("You have more than one dot in our Email please remove it thanks","More Dots Detected")
        Return
    End If
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
lease help how can i count number of dots i have in my email please help
You code would have worked if you escaped the dot. See the code below I corrected for you. This is not better than what Brian or Angel offered. It is just another way to stay with your line of thinking:
B4X:
Dim name As String =" I decided. to check .out this thread. because it. has a lot. of unnecessary .dots"
    Dim arrName() As String=Regex.Split("\.",name)    '<-----
    Log($"Number of dots: ${arrName.Length-1}"$)   'displays 6
    If arrName.Length-1 >1 Then
        MsgboxAsync("You have more than one dot in our Email please remove it thanks","More Dots Detected")
        Return
    End If
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Why not use email validation as perfomed here?
And I use this:
 
Upvote 0
Top