util工具
来源:互联网 发布:安卓锁屏软件 编辑:程序博客网 时间:2024/05/21 01:48
import java.util.regex.Matcher;import java.util.regex.Pattern;/** * @Description: StringUtil工具类 * @author: mengmei */public class StringUtil {/*** @Description: 特殊字符转换* @param str* @return* @return String * @throws */public static String translate(String str){if (str == null) {return "";}return str.replace("\r\n", " ").replace("\r", " ").replace("|", " ");}/** * * @Description: 判断字符串是否不为空* @param str* @return* @return boolean * @throws */public static boolean isNotNull(String str){return !(str == null || str.trim().length() == 0);}/** * * @Description: 判断字符串是否为空* @param str* @return* @return boolean * @throws */public static boolean isNull(String str){return str == null || str.trim().length() == 0 ;}/** * * @Description: 清除掉所有特殊字符* @param str* @return* @return String * @throws */public static String stringFilter(String str){String regx = "[;\\\\\;、,,]";Pattern pattern = Pattern.compile(regx);Matcher matcher = pattern.matcher(str);return matcher.replaceAll("|").trim();}/** * * @Description: 将对象转换为字符串* @param obj* @return* @return String * @throws */public static String nvl(Object obj){return obj == null ? "" :obj.toString().trim();}/** * * @Description: 判断2个字符串是否相等* @param str* @param other* @return* @return boolean * @throws */public static boolean isEq(String str, String other){if (str == null) {return other == null;}return str.equals(other);}/** * * @Description: 去掉路径,只返回文件名称* @param fileName* @return* @return String * @throws */public static String getFileName(String fileName){String fileNameRet = "";int index = 0;if (isNotNull(fileName)) {index = fileName.lastIndexOf("/");fileNameRet = fileName.substring(index + 1, fileName.length());}else {fileNameRet = fileName;}return fileNameRet;}/** * * @Description: 正则表达式校验* @param str* @param regx* @return* @return boolean * @throws */public static boolean matchRegx(String str, String regx){if (str == null || regx == null) {return false;}Pattern pattern = Pattern.compile(regx);Matcher matcher = pattern.matcher(str);return matcher.matches();}/** * * @Description: 特殊字符处理* @param str* @return* @return String * @throws */public static String replaceCharacter(String str){if (isNull(str)) {return " ";}return str.replace('\r', ' ').replace('\n', ' ');}/** * * @Description: 判断字符串是否为数字* @param str* @return* @return boolean * @throws */public static boolean checkNumber(String str){//1. -?[\\d]+ 可匹配所有正数、负数数字//2. [\\d]+ 可匹配所有正数数字//3. -?[\\d]+.?[\\d]+ 可匹配所有数字,包括小数String regx = "-?[\\d]+.?[\\d]+";Pattern pattern = Pattern.compile(regx);Matcher matcher = pattern.matcher(str);return matcher.matches();}}
阅读全文
0 0
- util工具
- 加密Util工具。
- java util工具类
- Util工具类
- 工具类util
- java.util其他工具类
- java.util.Timer工具类
- util 工具类(更新中............)
- java.util.Properties工具类
- 一些常用的UTIL工具
- 【util】工具类方法 总结
- android 的Util工具类
- Java.util.Collections工具类
- java.util.Objects工具类
- nodeJs常用util工具函数
- SharedPreferences util工具类封装
- 10node.js工具类util.inherits和util.inspect
- DWR之UTIL.JS工具方法
- 数据结构:表
- api gateway源码解析
- 5.Spring配置文件
- python3爬虫初探(二)之requests
- Golang
- util工具
- Golang学习之在项目中遇到的几个常用的方法
- iOS 解决按钮背景图拉伸问题
- 设计算法,把十进制整数转换为二至九进制之间的任一进制输出。
- npm无响应解决方案和nvm下载无响应
- SpringMVC——接收请求参数和页面传参
- NoSQL等于没有安全?大数据安全隐患分析
- Delphi中文件名函数-路径、名称、子目录、驱动器、扩展名
- 记录一下遇到过的问题