I have a string "552 s hello" I want to get the "552" in one substring and "s" in other substring and I want to split this String on the basis of first two spaces.Please help...

有帮助吗?

解决方案 2

Use String#split(String regex):

 String[] sp="552 s hello".split(" ");
 String fiveFiveTwo=sp[0];
 String letterS=sp[1];

The names aren't very useful in the end, so you'll want to rename the strings I've created. You should also catch ArrayIndexOutOfBoundsException.

其他提示

You can do it like this:

String t = "522 s hello"
String[] test = t.split(" ");

Now in the String array you will have three values, "522", "s" and "hello. And you can now access each.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top