我有
String s = "hello=goodmorning,2,1"
有人可以帮助我解决如何将s
拆分为以下内容的代码:
String s2 = "hello"
String s3 = "goodmorning"
string s4 = "2,1"
答案 0 :(得分: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
输出:
str1 = hello;
str3 = goodmorning;
str4 = 2,1;
答案 1 :(得分: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);
输出为2 1 3 4
答案 2 :(得分:0)
在Kotlin中添加
var s = "hello=goodmorning,2,1"
var str = s.split("=")