Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://aoindustries.com/contact
public final class StringUtility extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
compareToIgnoreCaseCarefulEquals(String S1,
String S2)
Compares two strings in a case insensitive manner.
|
static boolean |
containsIgnoreCase(String line,
String word) |
static byte[] |
convertByteArrayFromHex(char[] hex) |
static int |
convertIntArrayFromHex(char[] hex) |
static long |
convertLongArrayFromHex(char[] hex) |
static String |
convertToHex(byte[] bytes) |
static void |
convertToHex(byte[] bytes,
Appendable out) |
static String |
convertToHex(int value)
Converts an int to a full 8-character hex code.
|
static void |
convertToHex(int value,
Appendable out)
Converts an int to a full 8-character hex code.
|
static String |
convertToHex(long value)
Converts a long integer to a full 16-character hex code.
|
static void |
convertToHex(long value,
Appendable out)
Converts a long integer to a full 16-character hex code.
|
static int |
countOccurrences(byte[] buff,
int len,
String word)
Counts how many times a word appears in a line.
|
static int |
countOccurrences(byte[] buff,
String word)
Counts how many times a word appears in a line.
|
static int |
countOccurrences(String line,
String word)
Counts how many times a word appears in a line.
|
static String |
firstLineOnly(String value,
int maxCharacters)
Returns the first line only, and only up to the maximum number of characters.
|
static String |
getApproximateBitRate(long bit_rate)
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...
|
static String |
getApproximateSize(long size)
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...
|
static String |
getDecimalTimeLengthString(long time) |
static String |
getDecimalTimeLengthString(long time,
boolean alwaysShowMillis) |
static int |
getHex(char ch)
Converts one hex digit to an integer
|
static char |
getHexChar(int v)
Gets the hexadecimal character for the low-order four bits of the provided int.
|
static String |
getMonth(int month)
Deprecated.
This method is not locale-aware, is no longer used, and will be removed.
|
static String |
getTimeLengthString(long time) |
static int |
indexOf(String S,
char[] chars)
Finds the first occurrence of any of the supplied characters
|
static int |
indexOf(String S,
char[] chars,
int start)
Finds the first occurrence of any of the supplied characters starting at the specified index.
|
static int |
indexOf(String source,
String target,
int fromIndex,
int toIndex)
Finds the next of a substring like regular String.indexOf, but stops at a certain maximum index.
|
static String |
join(Iterable<?> objects,
String delimiter)
Joins the string representation of objects on the provided delimiter.
|
static <A extends Appendable> |
join(Iterable<?> objects,
String delimiter,
A out)
Joins the string representation of objects on the provided delimiter.
|
static String |
join(Object[] objects,
String delimiter)
Joins the string representation of objects on the provided delimiter.
|
static <A extends Appendable> |
join(Object[] objects,
String delimiter,
A out)
Joins the string representation of objects on the provided delimiter.
|
static String |
nullIfEmpty(String value)
Returns null if the string is null or empty.
|
static void |
replace(StringBuffer sb,
String find,
String replacement)
Replaces all occurrences of a String with a String.
|
static void |
replace(StringBuilder sb,
String find,
String replacement)
Replaces all occurrences of a String with a String.
|
static String |
replace(String string,
char ch,
String replacement)
Replaces all occurrences of a character with a String
|
static String |
replace(String string,
String find,
String replacement)
Replaces all occurrences of a String with a String
Please consider the variant with the Appendable for higher performance.
|
static void |
replace(String string,
String find,
String replacement,
Appendable out)
Replaces all occurrences of a String with a String, appends the replacement
to
out. |
static List<String> |
splitLines(String S)
Splits a String into lines on any '\n' characters.
|
static String[] |
splitString(String line)
Splits a
String into a String[]. |
static List<String> |
splitString(String line,
char delim)
Splits a string on the given delimiter.
|
static int |
splitString(String line,
char[][][] buff)
Splits a
String into a String[]. |
static <C extends Collection<String>> |
splitString(String line,
char delim,
C words)
Splits a string on the given delimiter.
|
static List<String> |
splitString(String line,
int begin,
int end,
char delim)
Splits a string on the given delimiter over the given range.
|
static <C extends Collection<String>> |
splitString(String line,
int begin,
int end,
char delim,
C words)
Splits a string on the given delimiter over the given range.
|
static List<String> |
splitString(String line,
String delim) |
static int |
splitString(String line,
String[][] buff)
Splits a
String into a String[]. |
static List<String> |
splitStringCommaSpace(String line)
Splits a string into multiple words on either whitespace or commas
|
static String |
wordWrap(String string,
int width)
Deprecated.
Use new version with Appendable for higher performance
|
static void |
wordWrap(String string,
int width,
Appendable out)
Word wraps a
String to be no longer than the provided number of characters wide. |
@Deprecated public static String getMonth(int month)
public static String join(Iterable<?> objects, String delimiter) throws ConcurrentModificationException
ConcurrentModificationException - if iteration is not consistent between passesjoin(java.lang.Iterable, java.lang.String, java.lang.Appendable),
join(java.lang.Object[], java.lang.String)public static <A extends Appendable> A join(Iterable<?> objects, String delimiter, A out) throws IOException
public static String join(Object[] objects, String delimiter) throws ConcurrentModificationException
ConcurrentModificationException - if iteration is not consistent between passesjoin(java.lang.Object[], java.lang.String, java.lang.Appendable),
join(java.lang.Iterable, java.lang.String)public static <A extends Appendable> A join(Object[] objects, String delimiter, A out) throws IOException
public static int countOccurrences(byte[] buff,
int len,
String word)
public static int countOccurrences(byte[] buff,
String word)
public static int countOccurrences(String line, String word)
public static String getTimeLengthString(long time)
public static String getDecimalTimeLengthString(long time)
public static String getDecimalTimeLengthString(long time, boolean alwaysShowMillis)
public static int indexOf(String S, char[] chars)
S - the String to searchchars - the characters to look for-1 if none foundpublic static int indexOf(String S, char[] chars, int start)
S - the String to searchchars - the characters to look forstart - the starting index.-1 if none foundpublic static String replace(String string, char ch, String replacement)
public static String replace(String string, String find, String replacement)
public static void replace(String string, String find, String replacement, Appendable out) throws IOException
out.IOExceptionpublic static void replace(StringBuffer sb, String find, String replacement)
public static void replace(StringBuilder sb, String find, String replacement)
public static List<String> splitLines(String S)
public static int splitString(String line, char[][][] buff)
String into a String[].public static int splitString(String line, String[][] buff)
String into a String[].public static List<String> splitString(String line, char delim)
public static <C extends Collection<String>> C splitString(String line, char delim, C words)
words - the words will be added to this collection.public static List<String> splitString(String line, int begin, int end, char delim)
public static <C extends Collection<String>> C splitString(String line, int begin, int end, char delim, C words)
words - the words will be added to this collection.public static List<String> splitStringCommaSpace(String line)
line - java.lang.String@Deprecated public static String wordWrap(String string, int width)
String to be no longer than the provided number of characters wide.public static void wordWrap(String string, int width, Appendable out) throws IOException
String to be no longer than the provided number of characters wide.
TODO: Make this more efficient by eliminating the internal use of substring.IOExceptionpublic static char getHexChar(int v)
public static int getHex(char ch)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static void convertToHex(byte[] bytes,
Appendable out)
throws IOException
IOExceptionpublic static String convertToHex(byte[] bytes)
public static byte[] convertByteArrayFromHex(char[] hex)
public static void convertToHex(int value,
Appendable out)
throws IOException
IOExceptionpublic static String convertToHex(int value)
public static int convertIntArrayFromHex(char[] hex)
public static void convertToHex(long value,
Appendable out)
throws IOException
IOExceptionpublic static String convertToHex(long value)
public static long convertLongArrayFromHex(char[] hex)
public static String getApproximateSize(long size)
public static String getApproximateBitRate(long bit_rate)
public static int compareToIgnoreCaseCarefulEquals(String S1, String S2)
public static int indexOf(String source, String target, int fromIndex, int toIndex)
public static String firstLineOnly(String value, int maxCharacters)
Copyright © 2000–2019 AO Industries, Inc.. All rights reserved.