java.lang.Object
com.aoapps.lang.Strings
- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares two strings in a case insensitive manner.static booleancontainsIgnoreCase(String line, String word) static byte[]convertByteArrayFromHex(char[] hex) Deprecated.static intconvertIntArrayFromHex(char[] hex) Deprecated.Please useHexstatic longconvertLongArrayFromHex(char[] hex) Deprecated.Please useHexstatic StringconvertToHex(byte[] bytes) Deprecated.Please useHexstatic voidconvertToHex(byte[] bytes, Appendable out) Deprecated.Please useHexstatic StringconvertToHex(int value) Deprecated.Please useHexstatic voidconvertToHex(int value, Appendable out) Deprecated.Please useHexstatic StringconvertToHex(long value) Deprecated.Please useHexstatic voidconvertToHex(long value, Appendable out) Deprecated.Please useHexstatic intcountOccurrences(byte[] buff, int len, String word) Counts how many times a word appears in a line.static intcountOccurrences(byte[] buff, String word) Counts how many times a word appears in a line.static intcountOccurrences(String line, String word) Counts how many times a word appears in a line.static StringfirstLineOnly(String value, int maxCharacters) Returns the first line only, and only up to the maximum number of characters.static StringgetApproximateBitRate(long bitRate) Gets the approximate bit rate (where k=1000).static StringgetApproximateSize(long size) Gets the approximate size (where k=1024) of a file.static StringgetDecimalTimeLengthString(long time) static StringgetDecimalTimeLengthString(long time, boolean alwaysShowMillis) static intgetHex(char ch) Deprecated.Please useHexstatic chargetHexChar(int v) Deprecated.Please useHexstatic StringgetMonth(int month) Deprecated.This method is not locale-aware, is no longer used, and will be removed.static StringgetTimeLengthString(long time) static intFinds the first occurrence of any of the supplied characters.static intFinds the first occurrence of any of the supplied characters starting at the specified index.static intFinds the next of a substring like regular String.indexOf, but stops at a certain maximum index.static intFinds the first occurrence of any of the supplied characters.static intFinds the first occurrence of any of the supplied characters starting at the specified index.static booleanisWhitespace(char ch) Determines if a character is whitespace.static booleanisWhitespace(int codePoint) Determines if a code point is whitespace.static StringJoins the string representation of objects on the provided delimiter.static <A extends Appendable>
AJoins the string representation of objects on the provided delimiter.static StringJoins the string representation of objects on the provided delimiter.static <A extends Appendable>
AJoins the string representation of objects on the provided delimiter.static StringnullIfEmpty(String value) Returns null if the string is null or empty.static voidreplace(StringBuffer sb, String find, String replacement) Replaces all occurrences of a String with a String.static voidreplace(StringBuilder sb, String find, String replacement) Replaces all occurrences of a String with a String.static StringReplaces all occurrences of a character with a String.static voidreplace(String string, char find, String replacement, Appendable out) Replaces all occurrences of a character with a String, appends the replacement toout.static voidreplace(String string, char find, String replacement, Appendable out, Encoder encoder) Replaces all occurrences of a character with a String, appends the replacement toout.static StringReplaces all occurrences of a String with a String.static voidreplace(String string, String find, String replacement, Appendable out) Replaces all occurrences of a String with a String, appends the replacement toout.static voidReplaces all occurrences of a String with a String, appends the replacement toout.static String[]Splits aStringinto aString[].Splits a string on the given delimiter.static intDeprecated.It is highly unlikely this method is still usedstatic <C extends Collection<String>>
CSplits a string on the given delimiter.Splits a string on the given delimiter over the given range.static <C extends Collection<String>>
CSplits a string on the given delimiter over the given range.static intDeprecated.It is highly unlikely this method is still usedsplitCommaSpace(String line) Splits a string into multiple words on either whitespace or commas.splitLines(String s) Splits a String into lines on any '\n' characters.static CharSequencetrim(CharSequence value) Trims a value, as per rules ofisWhitespace(int).static StringTrims a value, as per rules ofisWhitespace(int).static CharSequencetrimNullIfEmpty(CharSequence value) Trims a value, as per rules ofisWhitespace(int), returningnullif empty after trimming.static StringtrimNullIfEmpty(String value) Trims a value, as per rules ofisWhitespace(int), returningnullif empty after trimming.static StringDeprecated.Use new version with Appendable for higher performancestatic voidwordWrap(String string, int width, Appendable out) Word wraps aStringto be no longer than the provided number of characters wide.
-
Method Details
-
getMonth
Deprecated.This method is not locale-aware, is no longer used, and will be removed. -
join
public static String join(Iterable<?> objects, String delimiter) throws ConcurrentModificationException Joins the string representation of objects on the provided delimiter. The iteration will be performed twice. Once to compute the total length of the resulting string, and the second to build the result.- Throws:
ConcurrentModificationException- if iteration is not consistent between passes- See Also:
-
join
public static <A extends Appendable> A join(Iterable<?> objects, String delimiter, A out) throws IOException Joins the string representation of objects on the provided delimiter.- Throws:
IOException- See Also:
-
join
public static String join(Object[] objects, String delimiter) throws ConcurrentModificationException Joins the string representation of objects on the provided delimiter. The iteration will be performed twice. Once to compute the total length of the resulting string, and the second to build the result.- Throws:
ConcurrentModificationException- if iteration is not consistent between passes- See Also:
-
join
public static <A extends Appendable> A join(Object[] objects, String delimiter, A out) throws IOException Joins the string representation of objects on the provided delimiter.- Throws:
IOException- See Also:
-
containsIgnoreCase
-
countOccurrences
Counts how many times a word appears in a line. Case insensitive matching. -
countOccurrences
Counts how many times a word appears in a line. Case insensitive matching. -
countOccurrences
Counts how many times a word appears in a line. Case insensitive matching. -
getTimeLengthString
-
getDecimalTimeLengthString
-
getDecimalTimeLengthString
-
indexOf
Finds the first occurrence of any of the supplied characters.- Parameters:
s- theStringto searchchars- the characters to look for- Returns:
- the index of the first occurrence of
-1if none found
-
indexOf
Finds the first occurrence of any of the supplied characters starting at the specified index.- Parameters:
s- theStringto searchchars- the characters to look forstart- the starting index.- Returns:
- the index of the first occurrence of
-1if none found
-
indexOf
Finds the first occurrence of any of the supplied characters.- Parameters:
s- theStringto searchchars- the characters to look for- Returns:
- the index of the first occurrence of
-1if none found
-
indexOf
Finds the first occurrence of any of the supplied characters starting at the specified index.- Parameters:
s- theStringto searchchars- the characters to look forstart- the starting index.- Returns:
- the index of the first occurrence of
-1if none found
-
replace
Replaces all occurrences of a character with a String. Please consider the variant with theAppendablefor higher performance. -
replace
Replaces all occurrences of a String with a String. Please consider the variant with theAppendablefor higher performance. -
replace
public static void replace(String string, char find, String replacement, Appendable out) throws IOException Replaces all occurrences of a character with a String, appends the replacement toout.- Throws:
IOException
-
replace
public static void replace(String string, String find, String replacement, Appendable out) throws IOException Replaces all occurrences of a String with a String, appends the replacement toout.- Throws:
IOException
-
replace
public static void replace(String string, char find, String replacement, Appendable out, Encoder encoder) throws IOException Replaces all occurrences of a character with a String, appends the replacement toout.- Throws:
IOException
-
replace
public static void replace(String string, String find, String replacement, Appendable out, Encoder encoder) throws IOException Replaces all occurrences of a String with a String, appends the replacement toout.- Throws:
IOException
-
replace
Replaces all occurrences of a String with a String. -
replace
Replaces all occurrences of a String with a String. -
splitLines
Splits a String into lines on any '\n' characters. Also removes any ending '\r' characters if present -
split
Splits aStringinto aString[].- See Also:
-
split
Deprecated.It is highly unlikely this method is still usedSplits aStringinto aString[].- See Also:
-
split
Deprecated.It is highly unlikely this method is still usedSplits aStringinto aString[].- See Also:
-
split
Splits a string on the given delimiter. Does include all empty elements on the split.- Returns:
- the modifiable list from the split
-
split
Splits a string on the given delimiter. Does include all empty elements on the split.- Parameters:
words- the words will be added to this collection.- Returns:
- the collection provided in words parameter
-
split
Splits a string on the given delimiter over the given range. Does include all empty elements on the split.- Returns:
- the modifiable list from the split
-
split
public static <C extends Collection<String>> C split(String line, int begin, int end, char delim, C words) Splits a string on the given delimiter over the given range. Does include all empty elements on the split.- Parameters:
words- the words will be added to this collection.- Returns:
- the collection provided in words parameter
-
split
-
splitCommaSpace
Splits a string into multiple words on either whitespace or commas.- Returns:
- The list of non-empty strings.
- See Also:
-
wordWrap
Deprecated.Use new version with Appendable for higher performanceWord wraps aStringto be no longer than the provided number of characters wide. -
wordWrap
Word wraps aStringto be no longer than the provided number of characters wide.TODO: Make this more efficient by eliminating the internal use of substring.
- Throws:
IOException
-
getHexChar
Deprecated.Please useHexGets the hexadecimal character for the low-order four bits of the provided int. -
getHex
Deprecated.Please useHexConverts one hex digit to an integer.- Throws:
IllegalArgumentException
-
convertToHex
Deprecated.Please useHex- Throws:
IOException
-
convertToHex
Deprecated.Please useHex -
convertByteArrayFromHex
Deprecated.Please useHex -
convertToHex
Deprecated.Please useHexConverts an int to a full 8-character hex code.- Throws:
IOException
-
convertToHex
Deprecated.Please useHexConverts an int to a full 8-character hex code. -
convertIntArrayFromHex
Deprecated.Please useHex -
convertToHex
Deprecated.Please useHexConverts a long integer to a full 16-character hex code.- Throws:
IOException
-
convertToHex
Deprecated.Please useHexConverts a long integer to a full 16-character hex code. -
convertLongArrayFromHex
Deprecated.Please useHex -
getApproximateSize
Gets the approximate size (where k=1024) of a file. In this format:x byte(s) xx bytes xxx bytes x.x k xx.x k xxx k x.x M xx.x M xxx M x.x G xx.x G xxx G x.x T xx.x T xxx T xxx... T
-
getApproximateBitRate
Gets the approximate bit rate (where k=1000). In this format:x xx xxx x.x k xx.x k xxx k x.x M xx.x M xxx M x.x G xx.x G xxx G x.x T xx.x T xxx T xxx... T
-
compareToIgnoreCaseCarefulEquals
Compares two strings in a case insensitive manner. However, if they are considered equals in the case-insensitive manner, the case sensitive comparison is done. -
indexOf
Finds the next of a substring like regular String.indexOf, but stops at a certain maximum index. Like substring, will look up to the character one before toIndex. -
firstLineOnly
Returns the first line only, and only up to the maximum number of characters. If the value is modified, will append a horizontal ellipsis (Unicode 0x2026). -
nullIfEmpty
Returns null if the string is null or empty. -
isWhitespace
public static boolean isWhitespace(char ch) Determines if a character is whitespace. A character is considered whitespace if it is either<= ' '(for compatibility withString.trim()) or matchesCharacter.isWhitespace(char). -
isWhitespace
public static boolean isWhitespace(int codePoint) Determines if a code point is whitespace. A code point is considered whitespace if it is either<= ' '(for compatibility withString.trim()) or matchesCharacter.isWhitespace(int). -
trim
Trims a value, as per rules ofisWhitespace(int).- Returns:
- The value trimmed or
nullwhen wasnull - See Also:
-
trim
Trims a value, as per rules ofisWhitespace(int).- Returns:
- The value trimmed or
nullwhen wasnull - See Also:
-
trimNullIfEmpty
Trims a value, as per rules ofisWhitespace(int), returningnullif empty after trimming. -
trimNullIfEmpty
Trims a value, as per rules ofisWhitespace(int), returningnullif empty after trimming.
-

Hex