我有這樣one two three four
的字符串。我希望削減該字符串,使四根弦一樣one
,two
,three
和four
。我怎樣才能做到這一點?如何削減動態串
的字符串是一個動態的字符串。這個字符串的四個字改變了,因此我想爲任何字符串長度做適當的操作。
我有這樣one two three four
的字符串。我希望削減該字符串,使四根弦一樣one
,two
,three
和four
。我怎樣才能做到這一點?如何削減動態串
的字符串是一個動態的字符串。這個字符串的四個字改變了,因此我想爲任何字符串長度做適當的操作。
String[] strings;
String str = "one two three";
String delimiter = " ";
strings = str.split(delimiter);
謝謝:-),你是如此的幫助 – user1096087 2012-01-31 19:02:10
String[] strings = "one two three".split("\\B");
字符串有拆分方法。
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split%28java.lang.String%29
你傳遞給它代表你的分隔符正則表達式。爲了您的例子中,你可以這樣做:
String[] ar = string.split(" ");
string.split(),真的是你問A Q前,應谷歌搜索。 – L7ColWinters 2012-01-31 14:52:59
我建議再讀書前問[問完美提問](http://tinyurl.com/so-hints)... – sarnold 2012-01-31 23:54:27