“约翰”,“ 100.00”,“ 200.00”如何读取文本文件的内容,然后在引号下打印字符串。输出应为Jhon 100.00 200.00String CUSTOMER, CURRENT, NEW; Scanner sc = new Scanner(str); sc.useDelimiter(","); while(sc.hasNext()){ CUSTOMER = sc.next(); CURRENT = sc.next(); NEW = sc.next(); System.out.println("" + CUSTOMER + " " + CURRENT + " " + NEW); } sc.close();如何将标记与引号分开。我得到的上述代码的输出是“ Jhon”“ 100.00”“ 200.00”
2 回答
慕仙森
TA贡献1827条经验 获得超7个赞
您可以通过以下命令获得所需的输出:
public static void main(String[] args) {
Pattern p = Pattern.compile(".*?\\\"(.*?)\\\".*?");
Matcher m = p.matcher("\"John\",\"100.00\",\"200.00\"");
while (m.find()) {
System.out.println(m.group(1));
}
}
解释
.*? - anything
\\\" - quote (escaped)
(.*?) - anything (captured)
\\\" - another quote
.*? - anything
输出
John
100.00
200.00
添加回答
举报
0/150
提交
取消