| 发表于:2007-08-29 15:17:593楼 得分:5 |
java去除字符串中的空格、回车、换行符、制表符,本方法采用的是java的正则表达式 public class stringutil { public static void replaceblank() { pattern p = pattern.compile(\\s* ¦\t ¦\r ¦\n); string str= "i am a, i am hello ok, \n new line ffdsa! "; system.out.println( "before: "+str); matcher m = p.matcher(str); string after = m.replaceall( " "); system.out.println( "after: "+after); } public static void main(string[] args) { replaceblank(); } } | | |
|