package com.jaxc.scan;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReadTxtUtils{
public static void main(String[] args) {
String s = "我爱 五星红旗";
System.out.println(s.replaceAll(" ", ",").trim());
//处理后输出:我爱,,,,,,,,,,五星红旗
String regEx = "[' ']+"; // 一个或多个空格
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(s);
System.out.println(m.replaceAll(",").trim());
//处理后输出:我爱,五星红旗
}
}
处理字符串单个或多个空格替换