我需要删除标点读取文件,保持口音字符 我试过这个代码,但不工作我会怎么做。Java删除标点符号字符串(也是“”“和所有这些)保持重音字符
Expectation: input=> ’'qwe..,rty ‘èeéò’“ ”o" "à output=> qwertyèeéòoà
Effective result: input=> ’'qwe..,rty ‘èeéò’“ ”o" "à output=>’qwerty ‘èeéò’“ ”o" "à
我不能删除’“”
符号等这些
注:Eclipse
和filetext.txt
设置为UTF-8
。
谢谢
import java.io.*;
import java.util.Scanner;
public class DataCounterMain {
public static void main (String[] args) throws FileNotFoundException {
File file = new File("filetext.txt");
try {
Scanner filescanner = new Scanner(file);
while (filescanner.hasNextLine()) {
String line = filescanner.nextLine();
line=line.replaceAll ("\\p{Punct}", "");
System.out.println(line);
}
}
catch(FileNotFoundException e) {
System.err.println(file +" FileNotFound");
}
}
}
看来要删除所有Unicode标点和符号。使用'line = line.replaceAll(“(?U)[\\ p {S} \\ p {P}] +”,“”);' –