您的位置:首页 > 编程语言 > Java开发

java去除字符串中的空格、回车、换行符、制表符 .

2012-10-10 21:17 381 查看
/**

* 去除字符串中所包含的空格(包括:空格(全角,半角)、制表符、换页符等)

* @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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: