如何在 java 之后拆分特定字符串
How to split a specific string after in java
我有以下字符串:
String result = "@sequence@A:exampleA@B:exampleB";
我想将这个字符串分成两个字符串,如下所示:
String resulta = "sequence";
String resultb = "@A:exampleA@B:exampleB";
我该怎么做?我是 Java 编程语言的新手。
谢谢!
如果你想要典型的拆分,(特定于你的字符串),你可以调用子字符串并获取它的一部分,如下所示:
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);
}
Edit as per your comment
String s3= s.substring(s.indexOf("@",1));
System.out.println(s3);
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());
试试,
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);
我有以下字符串:
String result = "@sequence@A:exampleA@B:exampleB";
我想将这个字符串分成两个字符串,如下所示:
String resulta = "sequence";
String resultb = "@A:exampleA@B:exampleB";
我该怎么做?我是 Java 编程语言的新手。
谢谢!
如果你想要典型的拆分,(特定于你的字符串),你可以调用子字符串并获取它的一部分,如下所示:
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);
}
Edit as per your comment
String s3= s.substring(s.indexOf("@",1));
System.out.println(s3);
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());
试试,
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);