Android Question Get Text

B4X: Copy
Dim username As String = "Username: user4eir7yhm"
Dim password As String = "Password: uh6r0cdh"
Dim getUser() As String
getUser = Regex.Split(" ", username.Trim) 'Trim to eliminate blank spaces at the beginning and at the end of the string to parse
Dim getpw() As String
getpw = Regex.Split(" ", password.Trim) 'Trim to eliminate blank spaces at the beginning and at the end of the string to parse
Log(getUser(1))
Log(getpw(1))
It come obvious that all the Username and Password strings must have all the same format:
just ONE blank space after the ":" and no blank spaces inside the string.
 
Last edited:
Upvote 0
Another way to do it not necessarily better:
Code: Copy
Dim username As String = "Username: user4eir7yhm"
    Log(username.SubString(username.LastIndexOf(" ")))

Code: Copy
Dim password As String = "Password: uh6r0cdh"
    Log(password.SubString(password.LastIndexOf(" ")))

Edit: LastIndexOf(" ")) needs to be: LastIndexOf(" ")+1) to get rid of the space
 
Last edited:
Upvote 0
B4X: Copy
Dim username As String = "Username: user4eir7yhm"
Dim password As String = "Password: uh6r0cdh"
Dim getUser() As String
getUser = Regex.Split(" ", username.Trim) 'Trim to eliminate blank spaces at the beginning and at the end of the string to parse
Dim getpw() As String
getpw = Regex.Split(" ", password.Trim) 'Trim to eliminate blank spaces at the beginning and at the end of the string to parse
Log(getUser(1))
Log(getpw(1))
It come obvious that all the Username and Password strings must have all the same format:
just ONE blank space after the ":" and no blank spaces inside the string.

Your code, but only a bit optimized.
B4X: Copy
    Dim username As String = "Username: user4eir7yhm"
    Dim password As String = "Password: uh6r0cdh"
    Dim getUser() As String
    getUser = Regex.Split(":", username)
    Dim getpw() As String
    getpw = Regex.Split(":", password)
    Log(getUser(1).Trim) 'eliminate all blank spaces
    Log(getpw(1).Trim) 'eliminate all blank spaces
 
Upvote 0
Back
Top