使用引号分隔Java字符串 [英] Splitting Java string with quotation marks
本文介绍了使用引号分隔Java字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Java中分割String。分隔符是空格字符。
字符串可以包括成对的引号(内部包含一些文本和空格) - 成对引号内的整个主体应被视为单个标记。
例如:
I need to split the String in Java. The separator is the space character. String may include the paired quotation marks (with some text and spaces inside) - the whole body inside the paired quotation marks should be considered as the single token. Example:
Input:
token1 "token 2" token3
Output: array of 3 elements:
token1
token 2
token3
如何做?
谢谢!
How to do it? Thanks!
推荐答案
拆分两次。首先是引号,然后是空格。
Split twice. First on quotes, then on spaces.
这篇关于使用引号分隔Java字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文