我有以下字符串:
String result = "@sequence@A:exampleA@B:exampleB";
我想把这个字符串分成两个字符串,如下所示:
String resulta = "sequence";
String resultb = "@A:exampleA@B:exampleB";
我该怎么做?我是Java编程语言的新手。
谢谢!
答案 0 :(得分:0)
如果你想要典型的分割,(特定于你的字符串),你可以调用substring并获得它的一部分,如下所示:
String s = "@sequence@A:exampleA@B:exampleB";
String s1= s.substring(1,s.indexOf("@",1));
System.out.println(s1);
String s2= s.substring(s1.length()+1);
System.out.println(s2);
}
根据您的评论进行编辑
String s3= s.substring(s.indexOf("@",1));
System.out.println(s3);
答案 1 :(得分:0)
String result = "@sequence@A:exampleA@B:exampleB";
if(result.indexOf("@") == 0)
result = result.substring(1, result.length());
String resultA = result.substring(0, result.indexOf("@"));
String resultB = result.substring(resultA.length(), result.length());
答案 2 :(得分:0)
尝试,
String result = "@sequence@A:exampleA@B:exampleB", resulta, resultb;
int splitPoint = result.indexOf('@',1);
resulta = result.substring(1, splitPoint);
resultb = result.substring(splitPoint);
System.out.println(resulta+", "+resultb);