Remove space after the word in the Edit Text

lock255

Well-Known Member
Licensed User
Longtime User
Hi,

When I add a word with the edit text for example: Basic4android, my keyboard adds to the end of a word space. How can I check if you have added a space and prevent it from being added?
 

Mahares

Expert
Licensed User
Longtime User
Here is one way I would do it to check if there is a space at the end and use the trim function to get rid of it:
B4X:
txtTest.Text="lock255 "
If txtTest.Text.SubString(txtTest.Text.Length-1)=" " Then
  Msgbox(txtTest.Text & "You have a space at the end","")  '1st time you get this
Else
  Msgbox("no space","")
End If
txtTest.Text=txtTest.Text.Trim
If txtTest.Text.SubString(txtTest.Text.Length-1)=" " Then
  Msgbox("You have a space at the end","")
Else
  Msgbox(txtTest.Text & "no space","")  '2nd time you get this
End If
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
2nd choice is, to wipe the space char.

For this you can simply use
B4X:
Trim(EditText.Text)
 
Upvote 0

lock255

Well-Known Member
Licensed User
Longtime User
Thank you all for your answers, your codes are great. I especially thank Mahares.
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
Hey Gman: Your trim syntax is not correct. I already have the correct syntax in my post.

Was not a complete snippet, only wanted to give him a suggestion :sign0089:
 
Upvote 0
Top