How to get first name only from full name?

U

unba1300

Guest
Could someone please tell me how to determine only the first name from an edittext that contains a first and last name? I've only managed to do the opposite with IndexOf and SubString. Thanks.
 
U

unba1300

Guest
Although if only one name was entered into the edittext, I get a StringIndexOutOfBoundsException error, since there is no space found, I guess.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
That was a simple and quick solution, but yes, you will have to validate the existence of a First and Last Name, like this:

B4X:
If EditText1.Text.IndexOf(" ") > -1 Then

   FirstName = EditText1.Text.SubString2(0, EditText1.Text.IndexOf(" "))

   Msgbox("First Name is " & FirstName, "")

End If

Of course you can make this code more robust as needed.
 
Upvote 0
U

unba1300

Guest
Yep, I got it now. I came back to delete my last post, but you had replied already. Love these boards. Thanks again.
 
Upvote 0
Top