想象一下,我有这个字符串:
string thing = "sergio|tapia|gutierrez|21|Boston";
Run Code Online (Sandbox Code Playgroud)
在C#我可以去:
string[] Words = thing.Split('|');
Run Code Online (Sandbox Code Playgroud)
Java中有类似的东西吗?我可以使用Substring和indexOf方法,但它非常令人费解.我不希望这样.
您可以使用String.split.
String test = "a|b|c";
String[] splitStr = test.split("\\|"); // {"a", "b", "c"}
Run Code Online (Sandbox Code Playgroud)