类 StringUtil

java.lang.Object
com.weicoder.common.util.StringUtil
直接已知子类:
U.S

public class StringUtil extends Object
对字符串进行一些处理。
作者:
WD
  • 构造器详细资料

    • StringUtil

      public StringUtil()
  • 方法详细资料

    • containsEmoji

      public static boolean containsEmoji(String source)
      是否包含Emoji表情
      参数:
      source - 字符串
      返回:
      是否包含
    • filterEmoji

      public static String filterEmoji(String source)
      过滤掉Emoji表情
      参数:
      source - 字符串
      返回:
      过滤后的字符串
    • isEmojiCharacter

      public static boolean isEmojiCharacter(char codePoint)
      判断是否Emoji表情
      参数:
      codePoint - 检查字节
      返回:
      是否Emoji表情
    • startsWith

      public static boolean startsWith(String str, String prefix)
      判断字符串是否prefix开头
      参数:
      str - 字符串
      prefix - 开头字符串
      返回:
      是否开头
    • add

      public static String add(Object... os)
      字符串累加
      参数:
      os - 累加字符串
      返回:
      返回累加后字符串
    • add

      public static String add(String space, Object... os)
      字符串累加
      参数:
      space - 间隔符
      os - 累加字符串
      返回:
      返回累加后字符串 去空格
    • equals

      public static boolean equals(String str1, String str2)
      判断两个字符串是否相等 两个字符串都要不为空情况下才判断 都为空也为false
      参数:
      str1 - 第一个字符串
      str2 - 第二个字符串
      返回:
      true false
    • getLength

      public static int getLength(String str)
      返回字符串长度,汉字占两字节 主要是用于计算有汉字时的长度 一般情况下不使用,如果str为空返回0
      参数:
      str - 要校验长度的字符串
      返回:
      字符串长度
    • sub

      public static String sub(String str, String regex)
      使用正则表达式截取字符 截取第一个 如果没找到返回 ""
      参数:
      str - 要截取的字符串
      regex - 正则表达式
      返回:
      截取后的字符串
    • sub

      public static String sub(String str, String regex, int index)
      使用正则表达式截取字符 如果没找到返回 ""
      参数:
      str - 要截取的字符串
      regex - 正则表达式
      index - 截取组位置 重1开始
      返回:
      截取后的字符串
    • subAll

      public static String[] subAll(String str, String regex)
      使用正则表达式截取字符 获得全部匹配的
      参数:
      str - 要截取的字符串
      regex - 正则表达式
      返回:
      字符串数组
    • subString

      public static String subString(String str, String start, String end)
      从前截取字符串,如果str为空返回str

      注: 如果没有开始字符串 开始长度为0 如果没有结束字符串 结束长度为str长度

      注: 不包含开始与结束字符串

      参数:
      str - 要截取的字符串
      start - 开始截取的字符串
      end - 结束字符串
      返回:
      返回截取后的字符串
    • subString

      public static String subString(String str, int start)
      截取字符串
      参数:
      str - 字符串
      start - 开始字符
      返回:
      截取后的字符串
    • toParameters

      public static String toParameters(Map<String,?> map)
      根据Map获得URL后的参数 连接 如果值为空不连接 对Key进行排序
      参数:
      map - 参数列表
      返回:
      参数
    • subString

      public static String subString(String str, int start, int end)
      截取字符串
      参数:
      str - 字符串
      start - 开始字符
      end - 结束字符
      返回:
      截取后的字符串
    • subStringLast

      public static String subStringLast(String str, String start, String end)
      从后截取字符串,如果str为空返回str

      注: 如果没有开始字符串 开始长度为0 如果没有结束字符串 结束长度为str长度

      参数:
      str - 要截取的字符串
      start - 开始截取的字符串
      end - 结束字符串
      返回:
      返回截取后的字符串
    • subString

      public static String subString(String str, String start)
      从前截取字符串,如果str为空返回str

      注: 如果没有开始字符串 开始长度为0

      参数:
      str - 要截取的字符串
      start - 开始截取的字符串
      返回:
      返回截取后的字符串
    • subStringLast

      public static String subStringLast(String str, String start)
      从后截取字符串,如果str为空返回str

      注: 如果没有开始字符串 开始长度为0

      参数:
      str - 要截取的字符串
      start - 开始截取的字符串
      返回:
      返回截取后的字符串
    • subStringEnd

      public static String subStringEnd(String str, String end)
      从前截取字符串,如果str为空返回str

      注: 如果没有开始字符串 开始长度为0

      参数:
      str - 要截取的字符串
      end - 截取到的字符串
      返回:
      返回截取后的字符串
    • subStringLastEnd

      public static String subStringLastEnd(String str, String end)
      从后截取字符串,如果str为空返回str

      注: 如果没有开始字符串 开始长度为0

      参数:
      str - 要截取的字符串
      end - 截取到的字符串
      返回:
      返回截取后的字符串
    • toCharset

      public static String toCharset(String source, String tChar)
      转换字符串的编码格式 如果source为空 返回原串 如果转换异常返回原串
      参数:
      source - 要转换的字符串
      tChar - 转换编码
      返回:
      转换后的字符串
    • toCharset

      public static String toCharset(String source, String sChar, String tChar)
      转换字符串的编码格式 如果source为空 返回原串 如果转换异常返回原串
      参数:
      source - 要转换的字符串
      sChar - 原编码
      tChar - 转换编码
      返回:
      转换后的字符串
    • convert

      public static String convert(String name, String... regex)
      把输入的其它命名法变成驼峰命名法,如 User_Id = userId User = user 可以输入regex替换掉如 Init Action Rpc Aop 等
      参数:
      name - 属性名
      regex - 要替换掉的字符
      返回:
      转换后的字符串
    • convert

      public static String convert(String name)
      把输入的其它命名法变成驼峰命名法,如 User_Id = userId User = user
      参数:
      name - 属性名
      返回:
      转换后的字符串
    • toDbName

      public static String toDbName(String name)
      把驼峰命名转换为数据库名,如 userInfo = user_info
      参数:
      name - 属性名
      返回:
      转换后的字符串
    • toString

      public static String toString(byte[] b)
      转换字节数组为字符串
      参数:
      b - 字节数组
      返回:
      字符串
    • toString

      public static String toString(byte[] b, String charsetName)
      转换字节数组为字符串
      参数:
      b - 字节数组
      charsetName - 编码格式
      返回:
      字符串
    • toBytes

      public static byte[] toBytes(Object s)
      转换字符串为字节数组
      参数:
      s - 字符对象
      返回:
      字节数组
    • toBytes

      public static byte[] toBytes(String s)
      转换字符串为字节数组
      参数:
      s - 字符串
      返回:
      字节数组
    • toBytes

      public static byte[] toBytes(String s, String charsetName)
      转换字符串为字节数组
      参数:
      s - 字符串
      charsetName - 编码格式
      返回:
      字节数组
    • contains

      public static boolean contains(String str, String searchStr)
      判断str是否包含searchStr
      参数:
      str - 字符串
      searchStr - 被包含串
      返回:
      true 包含 false 不包含
    • trim

      public static String trim(String s)
      去除两边空格
      参数:
      s - 要处理的字符串
      返回:
      处理后的字符串
    • replace

      public static String replace(String s, String regex)
      替换字符串为""
      参数:
      s - 要替换的字符串
      regex - 正则表达式
      返回:
      替换后的字符
    • replace

      public static String replace(String s, String regex, String replacement)
      替换字符串
      参数:
      s - 要替换的字符串
      regex - 正则表达式
      replacement - 要替换掉的字符
      返回:
      替换后的字符
    • replaceAll

      public static String replaceAll(String s, String regex)
      替换字符串为""
      参数:
      s - 要替换的字符串
      regex - 正则表达式
      返回:
      替换后的字符
    • replaceAll

      public static String replaceAll(String s, String regex, String replacement)
      替换字符串
      参数:
      s - 要替换的字符串
      regex - 正则表达式
      replacement - 要替换掉的字符
      返回:
      替换后的字符
    • split

      public static String[] split(String s, String regex)
      拆分字符串
      参数:
      s - 要拆分的字符串
      regex - 正则表达式
      返回:
      替换后的字符
    • split

      public static String[] split(String s, String regex, String[] def)
      拆分字符串
      参数:
      s - 要拆分的字符串
      regex - 正则表达式
      返回:
      替换后的字符
    • getMethodName

      public static String getMethodName(String prefix, String name)
      获得方法名
      参数:
      prefix - 方法前缀 比如set get
      name - 方法的后缀名 比如字段名
      返回:
      方法名
    • resolve

      public static String resolve(String text, int len)
      分解字符串
      参数:
      text - 整串
      len - 新串的长度
      返回:
      新串
    • combine

      public static String combine(String s1, String s2)
      字符串结合
      参数:
      s1 - 字符串
      s2 - 字符串
      返回:
      返回聚合后字符串
    • combine

      public static String combine(String s1, String s2, int len)
      字符串结合
      参数:
      s1 - 字符串
      s2 - 字符串
      len - 合并长度
      返回:
      返回聚合后字符串
    • separate

      public static String[] separate(String s, int len)
      字符串拆分 分解combine方法结合的字符串
      参数:
      s - 要拆分的字符串
      len - 拆分长度
      返回:
      返回分开后字符串数组