0

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" 
1
  • post your attempts and define the logic. Commented Mar 23, 2015 at 16:16

3 Answers 3

1
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; 
Sign up to request clarification or add additional context in comments.

Comments

1

in kotlin add

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

Comments

0
 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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.