Package cn.yusiwen.commons.mapper
Class StrUtil
java.lang.Object
cn.yusiwen.commons.mapper.StrUtil
字符串工具类,提供常用的字符串处理方法。
- Author:
- Siwen Yu (yusiwen@gmail.com)
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcamel2Underscore(String camelStr) 驼峰模式字符串转换为下划线字符串static StringconvertCamel(String camelStr, char separator) 转换驼峰字符串为指定分隔符的字符串
如:camelStr:"UserInfo" separator:'_'
return "user_info"尝试将字符串解析为Long类型的数值static String截取字符串的子串,长度不超过指定的最大值。
-
Method Details
-
substr
截取字符串的子串,长度不超过指定的最大值。- Parameters:
str- 原始字符串,可以为 null。max- 子串的最大长度,不能为负。- Returns:
- 如果输入字符串为 null,返回 null;否则返回截取后的子串。
-
camel2Underscore
驼峰模式字符串转换为下划线字符串- Parameters:
camelStr- 驼峰字符串- Returns:
- 下划线字符串
-
convertCamel
转换驼峰字符串为指定分隔符的字符串
如:camelStr:"UserInfo" separator:'_'
return "user_info"- Parameters:
camelStr- 驼峰字符串separator- 分隔符- Returns:
- 将驼峰字符串转换后的字符串
-
parseLong
尝试将字符串解析为Long类型的数值- Parameters:
str- 要解析的字符串- Returns:
- 如果解析成功,返回包含Long值的Optional对象;如果解析失败,返回空的Optional对象
-