Class StrUtil

java.lang.Object
cn.yusiwen.commons.mapper.StrUtil

public class StrUtil extends Object
字符串工具类,提供常用的字符串处理方法。
Author:
Siwen Yu (yusiwen@gmail.com)
  • Method Details

    • substr

      public static String substr(String str, int max)
      截取字符串的子串,长度不超过指定的最大值。
      Parameters:
      str - 原始字符串,可以为 null。
      max - 子串的最大长度,不能为负。
      Returns:
      如果输入字符串为 null,返回 null;否则返回截取后的子串。
    • camel2Underscore

      public static String camel2Underscore(String camelStr)
      驼峰模式字符串转换为下划线字符串
      Parameters:
      camelStr - 驼峰字符串
      Returns:
      下划线字符串
    • convertCamel

      public static String convertCamel(String camelStr, char separator)
      转换驼峰字符串为指定分隔符的字符串
      如:camelStr:"UserInfo" separator:'_'
      return "user_info"
      Parameters:
      camelStr - 驼峰字符串
      separator - 分隔符
      Returns:
      将驼峰字符串转换后的字符串
    • parseLong

      public static Optional<Long> parseLong(String str)
      尝试将字符串解析为Long类型的数值
      Parameters:
      str - 要解析的字符串
      Returns:
      如果解析成功,返回包含Long值的Optional对象;如果解析失败,返回空的Optional对象