您的位置 首页 golang

分享两个公共方法 去除字符串全部空格,判断字符串是否有特殊字符

  1. package com.teamnavi.zstrade.common.util;

  2. import java.util.regex.Matcher;

  3. import java.util.regex. Pattern ;

  4. /**

  5. * 验证的公共方法

  6. * @author pts

  7. *

  8. */

  9. public class VerificationUtils {

  10. /**

  11. *

  12. * @param str 传入的 字符串

  13. * @return 返回没有空格的字符串

  14. */

  15. public static String removeSpaces(String str) {

  16. if(null!=str){

  17. String str2 = str.replaceAll(“\\s”, “”);

  18. return str2;

  19. }

  20. return str;

  21. }

  22. /**

  23. * 判断是否含有特殊字符

  24. *

  25. * @param str

  26. * @return true为包含,false为不包含

  27. */

  28. public static boolean isSpecialChar(String str) {

  29. String regEx = “[ _`~!@#$%^&*()+=|{}’:;’,\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t”;

  30. Pattern p = Pattern.compile(regEx);

  31. Matcher m = p.matcher(str);

  32. return m.find();

  33. }

  34. }

文章来源:智云一二三科技

文章标题:分享两个公共方法 去除字符串全部空格,判断字符串是否有特殊字符

文章地址:https://www.zhihuclub.com/86264.shtml

关于作者: 智云科技

热门文章

网站地图