0

I am writing an app with Android Studio and I want to split a text into different values. I have following text in result

*"Name: Peter;Age: 25; City: Chicago"*

I want to get:

*Name = Peter;
Age = 25;
City = Chicago;*

I used the search function and found these solutions: Android Split string but for my problem it seems to be too complicated.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sima
  • 13
  • 6

1 Answers1

1

The easiest way is to use split() method.

String s1="Name: Peter;Age: 25; City: Chicago"; 
String[] words=s1.split(";");
//using java foreach loop to print elements of string array  
for(String w:words)
{  
Log.i("Words: ", w); 
}  
Raj
  • 2,997
  • 2
  • 12
  • 30