public class StringUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
__ISO_8859_1 |
static java.lang.String |
__LINE_SEPARATOR
Deprecated.
use
System.lineSeparator() instead |
static java.lang.String |
__UTF16 |
static java.lang.String |
__UTF8 |
static java.lang.String |
ALL_INTERFACES |
static java.lang.String |
CRLF |
static char[] |
lowercases |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
append(java.lang.StringBuilder buf,
byte b,
int base)
append hex digit
|
static void |
append(java.lang.StringBuilder buf,
java.lang.String s,
int offset,
int length)
Append substring to StringBuilder
|
static void |
append2digits(java.lang.StringBuffer buf,
int i)
Append 2 digits (zero padded) to the StringBuffer
|
static void |
append2digits(java.lang.StringBuilder buf,
int i)
Append 2 digits (zero padded) to the StringBuilder
|
static java.lang.String[] |
arrayFromString(java.lang.String s)
Parse the string representation of a list using
csvSplit(List,String,int,int) |
static java.lang.String |
asciiToLowerCase(java.lang.String s)
fast lower case conversion.
|
static java.util.List<java.lang.String> |
csvSplit(java.util.List<java.lang.String> list,
java.lang.String s,
int off,
int len)
Split a quoted comma separated string to a list
|
static java.lang.String[] |
csvSplit(java.lang.String s)
Parse a CSV string using
csvSplit(List,String, int, int) |
static java.lang.String[] |
csvSplit(java.lang.String s,
int off,
int len)
Parse a CSV string using
csvSplit(List,String, int, int) |
static boolean |
endsWithIgnoreCase(java.lang.String s,
java.lang.String w) |
static boolean |
equals(java.lang.String s,
char[] buf,
int offset,
int length) |
static byte[] |
getBytes(java.lang.String s) |
static byte[] |
getBytes(java.lang.String s,
java.lang.String charset) |
static byte[] |
getUtf8Bytes(java.lang.String s) |
static int |
indexFrom(java.lang.String s,
java.lang.String chars)
returns the next index of a character from the chars string
|
static int |
indexOfControlChars(java.lang.String str)
Find the index of a control characters in String
|
static boolean |
isBlank(java.lang.String str)
Test if a string is null or only has whitespace characters in it.
|
static boolean |
isNotBlank(java.lang.String str)
Test if a string is not null and contains at least 1 non-whitespace characters in it.
|
static boolean |
isUTF8(java.lang.String charset) |
static java.lang.String |
nonNull(java.lang.String s)
Return a non null string.
|
static java.lang.String |
normalizeCharset(java.lang.String s)
Convert alternate charset names (eg utf8) to normalized
name (eg UTF-8).
|
static java.lang.String |
normalizeCharset(java.lang.String s,
int offset,
int length)
Convert alternate charset names (eg utf8) to normalized
name (eg UTF-8).
|
static java.lang.String |
printable(byte[] b) |
static java.lang.String |
printable(java.lang.String name) |
static java.lang.String |
replace(java.lang.String s,
java.lang.String sub,
java.lang.String with)
replace substrings within string.
|
static java.lang.String |
sanitizeXmlString(java.lang.String html) |
static java.lang.String |
sidBytesToString(byte[] sidBytes)
Deprecated.
|
static byte[] |
sidStringToBytes(java.lang.String sidString)
Deprecated.
|
static boolean |
startsWithIgnoreCase(java.lang.String s,
java.lang.String w) |
static int |
toInt(java.lang.String string,
int from)
Convert String to an integer.
|
static long |
toLong(java.lang.String string)
Convert String to an long.
|
static java.lang.String |
toString(byte[] b,
int offset,
int length,
java.lang.String charset) |
static java.lang.String |
toUTF8String(byte[] b,
int offset,
int length) |
static java.lang.String |
truncate(java.lang.String str,
int maxSize)
Truncate a string to a max size.
|
static java.lang.String |
unquote(java.lang.String s)
Deprecated.
|
static java.lang.String |
valueOf(java.lang.Object object)
The String value of an Object
|
public static final java.lang.String ALL_INTERFACES
public static final java.lang.String CRLF
@Deprecated public static final java.lang.String __LINE_SEPARATOR
System.lineSeparator()
insteadpublic static final java.lang.String __ISO_8859_1
public static final java.lang.String __UTF8
public static final java.lang.String __UTF16
public static final char[] lowercases
public static java.lang.String normalizeCharset(java.lang.String s)
s
- the charset to normalizepublic static java.lang.String normalizeCharset(java.lang.String s, int offset, int length)
s
- the charset to normalizeoffset
- the offset in the charsetlength
- the length of the charset in the input parampublic static java.lang.String asciiToLowerCase(java.lang.String s)
s
- the string to convertpublic static boolean startsWithIgnoreCase(java.lang.String s, java.lang.String w)
public static boolean endsWithIgnoreCase(java.lang.String s, java.lang.String w)
public static int indexFrom(java.lang.String s, java.lang.String chars)
s
- the input string to searchchars
- the chars to look forpublic static java.lang.String replace(java.lang.String s, java.lang.String sub, java.lang.String with)
s
- the input stringsub
- the string to look forwith
- the string to replace with@Deprecated public static java.lang.String unquote(java.lang.String s)
s
- the input stringpublic static void append(java.lang.StringBuilder buf, java.lang.String s, int offset, int length)
buf
- StringBuilder to append tos
- String to append fromoffset
- The offset of the substringlength
- The length of the substringpublic static void append(java.lang.StringBuilder buf, byte b, int base)
buf
- the buffer to append tob
- the byte to appendbase
- the base of the hex output (almost always 16).public static void append2digits(java.lang.StringBuffer buf, int i)
buf
- the buffer to append toi
- the value to appendpublic static void append2digits(java.lang.StringBuilder buf, int i)
buf
- the buffer to append toi
- the value to appendpublic static java.lang.String nonNull(java.lang.String s)
s
- Stringpublic static boolean equals(java.lang.String s, char[] buf, int offset, int length)
public static java.lang.String toUTF8String(byte[] b, int offset, int length)
public static java.lang.String toString(byte[] b, int offset, int length, java.lang.String charset)
public static int indexOfControlChars(java.lang.String str)
This will return a result on the first occurrence of a control character, regardless if there are more than one.
Note: uses codepoint version of Character.isISOControl(int)
to support Unicode better.
indexOfControlChars(null) == -1 indexOfControlChars("") == -1 indexOfControlChars("\r\n") == 0 indexOfControlChars("\t") == 0 indexOfControlChars(" ") == -1 indexOfControlChars("a") == -1 indexOfControlChars(".") == -1 indexOfControlChars(";\n") == 1 indexOfControlChars("abc\f") == 3 indexOfControlChars("z\010") == 1 indexOfControlChars(":") == 1
str
- the string to test.public static boolean isBlank(java.lang.String str)
Note: uses codepoint version of Character.isWhitespace(int)
to support Unicode better.
isBlank(null) == true isBlank("") == true isBlank("\r\n") == true isBlank("\t") == true isBlank(" ") == true isBlank("a") == false isBlank(".") == false isBlank(";\n") == false
str
- the string to test.public static boolean isNotBlank(java.lang.String str)
Note: uses codepoint version of Character.isWhitespace(int)
to support Unicode better.
isNotBlank(null) == false isNotBlank("") == false isNotBlank("\r\n") == false isNotBlank("\t") == false isNotBlank(" ") == false isNotBlank("a") == true isNotBlank(".") == true isNotBlank(";\n") == true
str
- the string to test.public static boolean isUTF8(java.lang.String charset)
public static java.lang.String printable(java.lang.String name)
public static java.lang.String printable(byte[] b)
public static byte[] getBytes(java.lang.String s)
public static byte[] getUtf8Bytes(java.lang.String s)
public static byte[] getBytes(java.lang.String s, java.lang.String charset)
@Deprecated public static java.lang.String sidBytesToString(byte[] sidBytes)
sidBytes
- the SID bytes to build from@Deprecated public static byte[] sidStringToBytes(java.lang.String sidString)
sidString
- the string SIDpublic static int toInt(java.lang.String string, int from)
string
- A String containing an integer.from
- The index to start parsing frompublic static long toLong(java.lang.String string)
string
- A String containing an integer.public static java.lang.String truncate(java.lang.String str, int maxSize)
str
- the string to possibly truncatemaxSize
- the maximum size of the stringstr
param is null, then the returned string will also be null.public static java.lang.String[] arrayFromString(java.lang.String s)
csvSplit(List,String,int,int)
s
- The string to parse, expected to be enclosed as '[...]'public static java.lang.String[] csvSplit(java.lang.String s)
csvSplit(List,String, int, int)
s
- The string to parsepublic static java.lang.String[] csvSplit(java.lang.String s, int off, int len)
csvSplit(List,String, int, int)
s
- The string to parseoff
- The offset into the string to start parsinglen
- The len in characters to parsepublic static java.util.List<java.lang.String> csvSplit(java.util.List<java.lang.String> list, java.lang.String s, int off, int len)
Handle rfc4180-like CSV strings, with the exceptions:
list
- The Collection to split to (or null to get a new list)s
- The string to parseoff
- The offset into the string to start parsinglen
- The len in characters to parsepublic static java.lang.String sanitizeXmlString(java.lang.String html)
public static java.lang.String valueOf(java.lang.Object object)
This method calls String.valueOf(Object)
unless the object is null,
in which case null is returned
object
- The objectCopyright © 1995–2023 Webtide. All rights reserved.