Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有一种简短的方法(可能是 str.split 变体)通过空格解析字符串,同时在引号之间绕过它?
示例:这应该拆分“这不是”等等
结果:
[0] - this; [1] - should; [2] - be; [3] - split; [4] - "this is not"; [5] - and; [6] - so; [7] - on;
谢谢
尝试这个:
String words = input.split(" +(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
仅当右侧有偶数个引号时才表示拆分。它不适合转义引号,但这并不难做到 - 只是变得非常难以阅读。