光环助手前端优化汇总(2019年12月)1~9.16.17 https://gitlab.ghzs.com/pm/halo-app-issues/issues/745
This commit is contained in:
@ -4,6 +4,8 @@ import android.util.Patterns;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import kotlin.text.Regex;
|
||||
|
||||
/**
|
||||
* @author CsHeng
|
||||
* @Date 17/05/2017
|
||||
@ -32,6 +34,25 @@ public class PatternUtils {
|
||||
Matcher matcher = Patterns.PHONE.matcher(phone);
|
||||
return matcher.matches();
|
||||
}
|
||||
/**
|
||||
* 判断字符串中是否有连续2个以上的空格 忽略 \t \r \n
|
||||
*/
|
||||
public static boolean isHasSpace(String text) {
|
||||
String pattern = "[\\s|\\t|\\r|\\n]{2,}";
|
||||
Regex regex = new Regex(pattern);
|
||||
return regex.find(text, 0) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换字符串中连续2个以上的空格为一个空格 忽略 \t \r \n
|
||||
*/
|
||||
public static String replaceSpace(String text) {
|
||||
String pattern = "[\\s|\\t|\\r|\\n]{2,}";
|
||||
String newText = text;
|
||||
if (isHasSpace(text)) {
|
||||
newText = text.replaceAll(pattern, " ");
|
||||
}
|
||||
return newText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user