String使用笔记

1.去掉字符串中的空格

str.trim()是去掉首尾空格

str.replace(" ", ""); 去掉所有空格,包括首尾、中间

replaceAll(" +",""); 去掉所有空格

str.replaceAll("\\s*", ""); 可以替换大部分空白字符,不只限于空格\s,还可以匹配空格、制表符、换页符等空白字符的其中任意一个

2.包含子字符串

tel.contains(phone); 返回true或者false。判断tel中是否包含phone子字符串

3.int型转String

int型转string,可以 +””

猜你喜欢

转载自blog.csdn.net/qq_37918817/article/details/83008380
今日推荐