org.test4j.tools.commons
类 StringHelper

java.lang.Object
  继承者 org.test4j.tools.commons.StringHelper

public class StringHelper
extends Object


字段摘要
static List<String> DEFAULT_EXCEPTION_FILTER
          默认的Exception信息过滤规则
static String EMPTY
           
 
构造方法摘要
StringHelper()
           
 
方法摘要
static String ascii2native(String asciiStr)
          将转义后的ascII字符串恢复成原始的是字符串
例如,转义后就是:我是中文
原始字符串为:我是中文
static String camel(String name)
          返回驼峰命名处理结果字符串
static String camel(String name, String... strings)
          返回驼峰命名处理结果字符串
static boolean compareWikiIgnoreSpace(String left, String right)
          比较2个wiki字符串是否相同(忽略换行)
static String deCamelCase(String wikiWord)
           
static String deleteWhitespace(String str)
           Deletes all whitespaces from a String as defined by Character.isWhitespace(char).
static boolean equals(String str1, String str2)
           Compares two Strings, returning true if they are equal.
static String exceptionTrace(Throwable e)
          把exception的trace信息写到string中
static String exceptionTrace(Throwable e, List<String> filters)
          把exception的trace信息写到string中,同时过滤掉filters中指定的信息
static String formatHtml(String html)
          把文本转义成正确格式的Html 比如:"<"转换成"<"等等
static String ignoreWhiteSpace(String str)
          忽略字符串中所有的空白符
static int indexOfWhiteSpace(String text)
           
static boolean isBlank(String str)
           
static boolean isBlankOrNull(String in)
          判断string是否为null或空字符串
static boolean isEmpty(String str)
           Checks if a String is empty ("") or null.
static boolean isSpace(char ch)
          是否是空白字符串
static boolean isWhiteSpaceCharacter(char c)
           
static String join(char seperator, char[] chars)
           
static String join(String seperator, String[] strings)
          合并字符串数组
static String ltrim(String source)
          去除开头的空白符,包括回车,换行符
static String merger(Iterable<?> items, char ch)
          将list中字符串以ch分割串在一起
static String merger(String[] strs, char ch)
           
static String native2ascii(String nativeStr)
          将原始字符串转义为ascII字符串
例如,原始字符串为:我是中文
转义后就是:我是中文
static int parseInt(String str, int _default)
           
static List<String> removeTheWhiteSpaces(List<String> original)
           
static String rtrim(String source)
          去除末尾的空白符,包括回车,换行符
static String rTrimSpace(String source)
          去除末尾的空白符,只包括空格和tab符
static String simpleDateStr(Timestamp time)
           
static String simpleDateTimeStr(long time)
           
static String simpleTimeStr(long time)
           
static String[] splits(String string, String splitStr)
          根据splitStr分割字符串string,并且过滤掉空串
static String substringAfterLast(String str, String separator)
           Gets the substring after the last occurrence of a separator.
static String toString(Object o)
          将对象转化为字符串{ddd,ddd}
static String toString(Throwable e)
          将exception转为string输出
static String trim(String source)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

EMPTY

public static final String EMPTY
另请参见:
常量字段值

DEFAULT_EXCEPTION_FILTER

public static final List<String> DEFAULT_EXCEPTION_FILTER
默认的Exception信息过滤规则

构造方法详细信息

StringHelper

public StringHelper()
方法详细信息

isBlankOrNull

public static boolean isBlankOrNull(String in)
判断string是否为null或空字符串

参数:
in -
返回:

trim

public static String trim(String source)

camel

public static String camel(String name)
返回驼峰命名处理结果字符串

参数:
name -
返回:

camel

public static String camel(String name,
                           String... strings)
返回驼峰命名处理结果字符串

参数:
name -
strings -
返回:

exceptionTrace

public static String exceptionTrace(Throwable e)
把exception的trace信息写到string中

参数:
e -
返回:
返回异常信息的序列化字符串

exceptionTrace

public static String exceptionTrace(Throwable e,
                                    List<String> filters)
把exception的trace信息写到string中,同时过滤掉filters中指定的信息

参数:
e -
filters -
返回:
返回异常信息的序列化字符串

simpleDateStr

public static String simpleDateStr(Timestamp time)

simpleDateTimeStr

public static String simpleDateTimeStr(long time)

simpleTimeStr

public static String simpleTimeStr(long time)

parseInt

public static int parseInt(String str,
                           int _default)

splits

public static String[] splits(String string,
                              String splitStr)
根据splitStr分割字符串string,并且过滤掉空串

参数:
string -
splitStr -
返回:

join

public static String join(String seperator,
                          String[] strings)
合并字符串数组

参数:
seperator -
strings -
返回:

join

public static String join(char seperator,
                          char[] chars)

formatHtml

public static String formatHtml(String html)
把文本转义成正确格式的Html 比如:"<"转换成"<"等等

参数:
html -
返回:
format后的文本

toString

public static String toString(Object o)
将对象转化为字符串{ddd,ddd}

参数:
o -
返回:

native2ascii

public static String native2ascii(String nativeStr)
将原始字符串转义为ascII字符串
例如,原始字符串为:我是中文
转义后就是:我是中文

参数:
nativeStr -
返回:

ascii2native

public static String ascii2native(String asciiStr)
将转义后的ascII字符串恢复成原始的是字符串
例如,转义后就是:我是中文
原始字符串为:我是中文

参数:
asciiStr -
返回:

deleteWhitespace

public static String deleteWhitespace(String str)

Deletes all whitespaces from a String as defined by Character.isWhitespace(char).

 StringUtils.deleteWhitespace(null)         = null
 StringUtils.deleteWhitespace("")           = ""
 StringUtils.deleteWhitespace("abc")        = "abc"
 StringUtils.deleteWhitespace("   ab  c  ") = "abc"
 

参数:
str - the String to delete whitespace from, may be null
返回:
the String without whitespaces, null if null String input

isEmpty

public static boolean isEmpty(String str)

Checks if a String is empty ("") or null.

 StringUtils.isEmpty(null)      = true
 StringUtils.isEmpty("")        = true
 StringUtils.isEmpty(" ")       = false
 StringUtils.isEmpty("bob")     = false
 StringUtils.isEmpty("  bob  ") = false
 

NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().

参数:
str - the String to check, may be null
返回:
true if the String is empty or null

equals

public static boolean equals(String str1,
                             String str2)

Compares two Strings, returning true if they are equal.

nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive.

 StringUtils.equals(null, null)   = true
 StringUtils.equals(null, "abc")  = false
 StringUtils.equals("abc", null)  = false
 StringUtils.equals("abc", "abc") = true
 StringUtils.equals("abc", "ABC") = false
 

参数:
str1 - the first String, may be null
str2 - the second String, may be null
返回:
true if the Strings are equal, case sensitive, or both null
另请参见:
String.equals(Object)

substringAfterLast

public static String substringAfterLast(String str,
                                        String separator)

Gets the substring after the last occurrence of a separator. The separator is not returned.

A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the empty string if the input string is not null.

If nothing is found, the empty string is returned.

 StringUtils.substringAfterLast(null, *)      = null
 StringUtils.substringAfterLast("", *)        = ""
 StringUtils.substringAfterLast(*, "")        = ""
 StringUtils.substringAfterLast(*, null)      = ""
 StringUtils.substringAfterLast("abc", "a")   = "bc"
 StringUtils.substringAfterLast("abcba", "b") = "a"
 StringUtils.substringAfterLast("abc", "c")   = ""
 StringUtils.substringAfterLast("a", "a")     = ""
 StringUtils.substringAfterLast("a", "z")     = ""
 

参数:
str - the String to get a substring from, may be null
separator - the String to search for, may be null
返回:
the substring after the last occurrence of the separator, null if null String input
从以下版本开始:
2.0

ignoreWhiteSpace

public static String ignoreWhiteSpace(String str)
忽略字符串中所有的空白符

参数:
input -
返回:

isSpace

public static final boolean isSpace(char ch)
是否是空白字符串

参数:
ch -
返回:

isBlank

public static final boolean isBlank(String str)

removeTheWhiteSpaces

public static List<String> removeTheWhiteSpaces(List<String> original)

deCamelCase

public static String deCamelCase(String wikiWord)

isWhiteSpaceCharacter

public static boolean isWhiteSpaceCharacter(char c)

indexOfWhiteSpace

public static int indexOfWhiteSpace(String text)

ltrim

public static String ltrim(String source)
去除开头的空白符,包括回车,换行符

参数:
source -
返回:

rtrim

public static String rtrim(String source)
去除末尾的空白符,包括回车,换行符

参数:
source -
返回:

rTrimSpace

public static String rTrimSpace(String source)
去除末尾的空白符,只包括空格和tab符

参数:
source -
返回:

toString

public static String toString(Throwable e)
将exception转为string输出

参数:
e -
返回:

compareWikiIgnoreSpace

public static boolean compareWikiIgnoreSpace(String left,
                                             String right)
比较2个wiki字符串是否相同(忽略换行)

参数:
left -
right -
返回:

merger

public static String merger(Iterable<?> items,
                            char ch)
将list中字符串以ch分割串在一起

参数:
items -
ch -
返回:

merger

public static String merger(String[] strs,
                            char ch)


Copyright © 2013. All rights reserved.