user6005229
user6005229

Reputation:

How to split a string from a specified place

I want to make a form in my android app with a field to enter name(not first name and last name). After getting the name, I want to split it into first name and last name. For example:

I got Jack Dawson as name.

Now I want to split it from the place where it contains space. i.e.

Upvotes: 1

Views: 53

Answers (1)

Panda
Panda

Reputation: 2510

Say for example the string is "Jack Dawson". Now, if you want to split it with spaces,

String currentString = "Jack Dawson";
String[] separated = currentString.split(" ");

This way, you will get an array of string where, seperated[0] = "Jack" and seperated[1] = "Dawson". I hope it solves your problem.

Upvotes: 2

Related Questions