美文网首页
java去除全角空格

java去除全角空格

作者: weft | 来源:发表于2016-09-20 16:47 被阅读0次

去除开头两个全角字符

while(firstPara.startsWith("  ")){
            firstPara = firstPara.substring(2, firstPara.length()).trim();
        }

以下来源于:http://blog.csdn.net/hfhwfw/article/details/5722487

/** 
 * 去除字符串中所包含的空格(包括:空格(全角,半角)、制表符、换页符等) 
 * @param s 
 * @return 
 */  
public static String removeAllBlank(String s){  
    String result = "";  
    if(null!=s && !"".equals(s)){  
        result = s.replaceAll("[ *| *| *|//s*]*", "");  
    }  
    return result;  
}  
  
/** 
 * 去除字符串中头部和尾部所包含的空格(包括:空格(全角,半角)、制表符、换页符等) 
 * @param s 
 * @return 
 */  
public static String trim(String s){  
    String result = "";  
    if(null!=s && !"".equals(s)){  
        result = s.replaceAll("^[ *| *| *|//s*]*", "").replaceAll("[ *| *| *|//s*]*$", "");  
    }  
    return result;  
}

相关文章

网友评论

      本文标题:java去除全角空格

      本文链接:https://www.haomeiwen.com/subject/oqeoettx.html