我有以下字符串:
"Sample text, another sample","勾","","勾"
我想得到4个子字符串,如下:
- 示例文本,另一个示例
- 勾
- //只是空字符串
- 勾
有人可以发布有关如何实现这一目标的解决方案吗?如果可能的话,您能否向我展示两种方法(标准方法和使用正则表达式)。非常感谢
最佳答案
String str = "\"Sample text, another sample\",\"勾\",\"\",\"勾\"";
Pattern pattern = Pattern.compile("\"([^\"]*)\"");
Matcher matcher = pattern.matcher(str);
while(matcher.find())
{
System.out.println(matcher.group(1));
}
关于java - String 中的 4 个子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17080052/