有沒有一個簡短的方法(也許str.split變化)解析一個字符串的空格,而繞過引號之間?解析不在逗號之間的空格的簡短方法?
例如: 這應該被拆分 「這不是」 等等
結果:
[0] - this; [1] - should; [2] - be; [3] - split; [4] - "this is not";
[5] - and; [6] - so; [7] - on;
感謝
有沒有一個簡短的方法(也許str.split變化)解析一個字符串的空格,而繞過引號之間?解析不在逗號之間的空格的簡短方法?
例如: 這應該被拆分 「這不是」 等等
結果:
[0] - this; [1] - should; [2] - be; [3] - split; [4] - "this is not";
[5] - and; [6] - so; [7] - on;
感謝
試試這個:
String words = input.split(" +(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
它的說法分裂只有在右側有偶數的引號時才適用。它不適合逃脫報價,但這並不難 - 只是變得很難閱讀。
你的意思是「在qoutes之間」。 – 2013-04-25 15:16:53
請參閱:http://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes – 2013-04-25 15:20:20
固定爲引用 – Mark 2013-04-25 15:21:06