buuMuhammed112
buuMuhammed112

Reputation: 21

Android split string into 2 strings

I have

String s = "hello=goodmorning,2,1"

can somebody help me with the code on how to split s to equal the following:

String s2 = "hello"
String s3 = "goodmorning"
string s4 = "2,1"

Upvotes: 0

Views: 12446

Answers (3)

user11716837
user11716837

Reputation:

in kotlin add

var s = "hello=goodmorning,2,1"
var str = s.split("=")

Upvotes: 1

Hitesh sapra
Hitesh sapra

Reputation: 256

 String s = "hello=goodmorning 2 1 3 4";
 String[] str = s.split(" "); 
 String str1 = str[0]; 
 String new1 =s.replace(str1,"");
 System.out.println(new1);

Output is 2 1 3 4

Upvotes: 0

Apurva
Apurva

Reputation: 7901

String s = "hello=goodmorning,2,1"

String[] str = s.split("=");  //now str[0] is "hello" and str[1] is "goodmorning,2,1"

String str1 = str[0];  //hello

String[] str2 = str[1].split(",");  //now str2[0] is "goodmorning" and str2[1] is "2,1"

String str3 = str2[0];  //goodmorning
String str4 = str2[1];  //2,1

Output:

str1 = hello;
str3 = goodmorning;
str4 = 2,1;

Upvotes: 1

Related Questions