处理字符串单个或多个空格替换
作者:互联网
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());
//处理后输出:我爱,五星红旗
}
}
处理字符串单个或多个空格替换
标签:trim,String,Pattern,System,空格,五星红旗,字符串,替换 来源: https://blog.csdn.net/qq_37176273/article/details/116355350