我正在使用Play框架並從textarea中獲取文本,我想將其分割爲輸入的單詞,空格和換行符的數組。如何將字符串拆分爲單詞,空格和換行符?
的Hello World
你好嗎
會像
a[0] = "Hello";
a[1] = " ";
a[2] = "World";
a[3] = " ";
a[4] = "How";
a[5] = "\n";
a[6] = "Are";
a[7] = " ";
a[8] = "You";
如果有一個簡單的正則表達式的方式或類似的東西我也喜歡聽到了嗎?
這似乎是http://stackoverflow.com/questions/275768/is-there-a-way-to-split-strings-with-string-split-and-include-the-的副本分隔符 – worpet 2011-04-13 01:55:49
這可能是解決方案。去看看它。 – 2011-04-13 01:59:11