Class Strings

java.lang.Object
com.globalmentor.java.Strings

public class Strings extends Object
Various text manipulating functions. These methods work on String objects, which are immutable heavyweight objects that must be recreated with every modification. Many of these methods should therefore be avoided in favor of their corresponding StringBuilders methods, which operate on StringBuilder objects.
Author:
Garret Wilson
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String[]
    A shared empty array of strings.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Returns the string or null if the string is the empty string ("").
    static String
    collapse(String inString, Characters collapseChars, String replaceString)
    Collapses every run of any number of collapseChars to a single replacement string.
    static String[]
    Creates an array of strings from the given string.
    static String
    createString(char firstChar, char lastChar)
    Creates a string containing a range of characters.
    static String
    createString(char ch, int count)
    Creates a string with a given repetition of characters.
    static final boolean
    equalsIgnoreCase(String string1, String string2)
    Compares two strings to make sure that the strings are equal without regard to case, or that the strings are both set to null.
    static String
    forceLength(String inString, int len, char ch)
    Ensures that the given string is the correct length by adding or deleting characters to or from the end.
    static String
    forceLength(String inString, int len, char ch, int pos)
    Ensures that the given string is the correct length by adding or deleting characters to or from the requested position.
    static byte[]
    getASCIIZBytes(String string, int length)
    Creates an array of bytes of the specified length and stores the bytes of the string, in UTF-8, in the array appended with a zero byte.
    static byte[]
    getASCIIZBytes(String string, int length, Charset charset)
    Creates an array of bytes of the specified length and stores the bytes of the string, in the array appended with a zero byte.
    getInputStream(String string, String encoding)
    Creates an input stream from which to read the given string.
    static int
    getWordBeginning(String inString, int index)
    Returns the beginning of the word at index.
    static int
    getWordEnd(String inString, int index)
    Returns the end of the word at index.
    static int
    indexOfIgnoreCase(String string, char c)
    Finds the index of a particular character, ignoring case.
    static int
    indexOfIgnoreCase(String string, char c, int fromIndex)
    Finds the index of a particular character, ignoring case, from a given index.
    static int
    indexOfIgnoreCase(String string, String substring)
    Finds the index of a particular substring, ignoring case.
    static int
    indexOfIgnoreCase(String string, String substring, int fromIndex)
    Finds the index of a particular substring, ignoring case, from a given index.
    static String
    insert(String inString, int index, char insertChar)
    Inserts a character at a specified index.
    static String
    insert(String inString, int index, String insertString)
    Inserts a string at a specified index.
    static int
    lastIndexOfIgnoreCase(String string, String substring, int fromIndex)
    Searches a string in reverse and returns the last index of a substring without case sensitivity, starting from fromIndex.
    static String
    Parses the string and finds any hyperlinks, to which it then creates and inserts the appropriate HTML tags.
    static String
    makeStringLength(String inString, int len, char ch)
    Deprecated.
    to be removed in favor of forceLength(String, int, char).
    static String
    makeStringLength(String inString, int len, char ch, int pos)
    Deprecated.
    to be removed in favor of forceLength(String, int, char, int).
    static String
    remove(String inString, int index)
    Removes a character at the specified index.
    static String
    remove(String inString, int index, int len)
    Removes several characters at the specified index.
    static String
    removeAfterFirstChar(String string, Characters delimiters)
    Removes all characters that come after and including the first occurrence of a character in the given delimiter string.
    static String
    removeBeforeLast(String string, char c)
    Removes all characters that come before the last occurrence of the given character.
    static String
    removeLengthIgnoreCase(String string, String substring)
    Removes the given substring, matched without case sensitivity, and everything following the string.
    static String
    replace(String string, char[] matchChars, String[] replacementStrings)
    Replaces each matching character with the corresponding replacement string.
    static String
    replace(String inString, char replaceChar, String withString)
    Replaces every occurrence of a specified character with a string.
    static String
    replace(String inString, int index, int len, String replaceString)
    Removes several characters at the specified index and replaces them with the given string.
    static String
    replace(String inString, Characters matchCharacters, char replacementChar)
    Replaces any of several matching characters with a particular character.
    static String
    replace(String inString, Characters matchCharacters, String replacementString)
    Replaces any of several matching characters with a particular string.
    static String
    replace(String inString, String replaceString, String withString)
    Replaces every occurrence of a specified string with another string.
    static boolean
    Determines whether the string starts with the given prefix, ignoring case.
    static final String
    stringOf(char... chars)
    Convenience method to create a string from characters using varargs.
    static String
    stringToken(String inString, int tokenNumber, Characters delimiters)
    Returns the specified numbered (one-based) token in the specified string, separated by delimiters.
    static String
    stringWord(String inString, int wordNumber)
    Returns the specified numbered (one-based) word in the specified string.
    static int
    tokenEndIndex(String inString, int tokenNumber, Characters delimiters)
    Returns the index right after the given numbered (one-based) token.
    static int
    tokenIndex(String inString, int tokenNumber, Characters delimiters)
    Returns the index of the given numbered (one-based) token.
    static String
    trim(String inString, Characters delimiters)
    Trims the specified delimiters from the beginning and end of the string.
    static String
    trimBeginning(String inString, char removeChar, int occurrence)
    Trims the left side of the string beginning at the specified occurrence of removeChar from the beginning.
    static String
    trimBeginning(String inString, String beginString)
    If the input string begins with the specifid string, trims that string.
    static String
    trimBeginningFirst(String inString, char removeChar)
    Trims the left side of the string beginning at the first occurrence of removeChar.
    static String
    trimBeginningLast(String inString, char removeChar)
    Trims the left side of the string beginning at the last occurrence of removeChar.
    static String
    trimEnd(String inString, char removeChar, int occurrence)
    Trims the right side of the string beginning at the specified occurrence of removeChar from the end.
    static String
    trimEnd(String inString, String endString)
    If the input string ends with the specified string, trims that string.
    static String
    trimEndFirst(String inString, char removeChar)
    Trims the right side of the string beginning at the first occurrence of removeChar.
    static String
    trimEndLast(String inString, char removeChar)
    Trims the right side of the string beginning at the last occurrence of removeChar.
    static String
    Trims whitespace, including the Unicode no-break space character 0x00A0, from the beginning and end of the string.
    static String
    Trims whitespace, including the Unicode no-break space character 0x00A0, from the beginning of the string.
    static String
    Trims whitespace, including the Unicode no-break space character 0x00A0, from the beginning of the string.
    static String
    truncate(String string, int maxLength)
    Truncates the string, if needed, to ensure that the string is no longer than the provided length.
    static String
    truncateChar(String string, Characters delimiters)
    Removes everything after and including the first occurrence of one of the given characters.
    static int
    wordEndIndex(String inString, int wordNumber)
    Returns the index right after the given numbered (one-based) word.
    static int
    wordIndex(String inString, int wordNumber)
    Returns the index of the given numbered (one-based) word.
    static String
    wrap(String inString, int wrapLength)
    Performs word-wrapping on the input string by strategically inserting ends-of-line, ensuring that each line is no longer than the specified length.
    static String
    wrap(String inString, int wrapLength, char padChar, char eolChar)
    Performs word-wrapping on the input string by strategically inserting ends-of-line, ensuring that each line is no longer than the specified length.
    static <T> String
    write(URI baseURI, T object, IO<T> io)
    Writes an object to a string using the given I/O support, converting bytes to a string using the UTF-8 charset.
    static <T> String
    write(URI baseURI, T object, IO<T> io, Charset charset)
    Writes an object to a string using the given I/O support.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NO_STRINGS

      public static final String[] NO_STRINGS
      A shared empty array of strings.
  • Method Details

    • asNonEmptyString

      public static String asNonEmptyString(String string)
      Returns the string or null if the string is the empty string ("").
      Parameters:
      string - The string to examine.
      Returns:
      string if the length of the string is greater than zero, otherwise null.
    • stringOf

      public static final String stringOf(char... chars)
      Convenience method to create a string from characters using varargs.
      Parameters:
      chars - The characters that should make up the string.
      Returns:
      A string created from the given characters.
      Throws:
      NullPointerException - if the given chars is null.
    • createArray

      public static String[] createArray(String string)
      Creates an array of strings from the given string.
      Parameters:
      string - The string to include in the array, or null if the array should be empty.
      Returns:
      A non-null array containing the string, or empty if the string is null.
    • equalsIgnoreCase

      public static final boolean equalsIgnoreCase(String string1, String string2)
      Compares two strings to make sure that the strings are equal without regard to case, or that the strings are both set to null. If the first string is not null, it is compared to the second using the first string's String.equalsIgnoreCase(String) method. This is a convenience method to compare two strings using the String.equalsIgnoreCase(String) method when it's not known if one of the strings is null.
      Parameters:
      string1 - The first string to compare.
      string2 - The second string to compare.
      Returns:
      true if the strings are equal according to the first string's String.equalsIgnoreCase(String) method or if both strings are null.
      See Also:
    • getASCIIZBytes

      public static byte[] getASCIIZBytes(String string, int length) throws UnsupportedEncodingException
      Creates an array of bytes of the specified length and stores the bytes of the string, in UTF-8, in the array appended with a zero byte. If the string is too long for the given length, it is truncated.
      Parameters:
      string - The string to store in bytes.
      length - The length of bytes to return.
      Returns:
      The array of bytes containing the bytes of the given string.
      Throws:
      UnsupportedEncodingException - Thrown if the given encoding is not supported.
    • getASCIIZBytes

      public static byte[] getASCIIZBytes(String string, int length, Charset charset) throws UnsupportedEncodingException
      Creates an array of bytes of the specified length and stores the bytes of the string, in the array appended with a zero byte. If the string is too long for the given length, it is truncated.
      Parameters:
      string - The string to store in bytes.
      length - The length of bytes to return.
      charset - The charset to use in storing the string bytes.
      Returns:
      The array of bytes containing the bytes of the given string.
      Throws:
      UnsupportedEncodingException - Thrown if the given encoding is not supported.
    • getInputStream

      public static InputStream getInputStream(String string, String encoding) throws UnsupportedEncodingException
      Creates an input stream from which to read the given string.
      Parameters:
      string - The string for which an input stream should be created.
      encoding - The encoding to use to turn the string into bytes.
      Returns:
      An input stream of the string bytes.
      Throws:
      UnsupportedEncodingException - Thrown if the given encoding is not supported.
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(String string, char c)
      Finds the index of a particular character, ignoring case.
      Parameters:
      string - The string to search.
      c - The character to search for.
      Returns:
      The index of the character ignoring case, or -1 if the character could not be found.
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(String string, char c, int fromIndex)
      Finds the index of a particular character, ignoring case, from a given index.
      Parameters:
      string - The string to search.
      c - The character to search for.
      fromIndex - The index at which to begin searching
      Returns:
      The index of the character ignoring case, or -1 if the character could not be found.
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(String string, String substring)
      Finds the index of a particular substring, ignoring case.
      Parameters:
      string - The string to search.
      substring - The string to search for.
      Returns:
      The index of the substring ignoring case, or -1 if the substring could not be found.
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(String string, String substring, int fromIndex)
      Finds the index of a particular substring, ignoring case, from a given index.
      Parameters:
      string - The string to search.
      substring - The string to search for.
      fromIndex - The index at which to begin searching
      Returns:
      The index of the substring ignoring case, or -1 if the substring could not be found.
    • insert

      public static String insert(String inString, int index, String insertString)
      Inserts a string at a specified index.
      Parameters:
      inString - the String into which the information will be inserted.
      index - The information will be inserted before the character that appears at this index.
      insertString - The string to insert.
      Returns:
      A new string with the specified information inserted at the specified location.
    • insert

      public static String insert(String inString, int index, char insertChar)
      Inserts a character at a specified index.
      Parameters:
      inString - the String into which the information will be inserted.
      index - The information will be inserted before the character that appears at this index.
      insertChar - The character to insert.
      Returns:
      A new string with the specified information inserted at the specified location.
    • lastIndexOfIgnoreCase

      public static int lastIndexOfIgnoreCase(String string, String substring, int fromIndex)
      Searches a string in reverse and returns the last index of a substring without case sensitivity, starting from fromIndex.
      Parameters:
      string - The string to be searched.
      substring - The substring for which to search.
      fromIndex - The index from which to search.
      Returns:
      The index of the last occurrence of the substring at or less than the given index, or -1 if none was found.
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(String string, String prefix)
      Determines whether the string starts with the given prefix, ignoring case.
      Parameters:
      string - The string to search.
      prefix - The starting string to check for.
      Returns:
      true if the string starts with the given prefix, ignoring case.
    • tokenIndex

      public static int tokenIndex(String inString, int tokenNumber, Characters delimiters)
      Returns the index of the given numbered (one-based) token.
      Parameters:
      inString - The string to search.
      tokenNumber - The number (one-based) of the token to find.
      delimiters - The characters to use for delimiters.
      Returns:
      The index of the specified token number, or -1 if that token was not found.
    • tokenEndIndex

      public static int tokenEndIndex(String inString, int tokenNumber, Characters delimiters)
      Returns the index right after the given numbered (one-based) token.
      Parameters:
      inString - The string to search.
      tokenNumber - The number (one-based) of the token to find.
      delimiters - The characters to use for delimiters.
      Returns:
      The index of one character past the last character of the specified token number, or -1 if that token was not found.
    • stringToken

      public static String stringToken(String inString, int tokenNumber, Characters delimiters)
      Returns the specified numbered (one-based) token in the specified string, separated by delimiters.
      Parameters:
      inString - The string to search.
      tokenNumber - The number (one-based) of the token to find.
      delimiters - The characters to use for delimiters.
      Returns:
      The specified numbered (one-based) token in the specified string, separated by delimiters, or "" if that token was not found.
    • wordIndex

      public static int wordIndex(String inString, int wordNumber)
      Returns the index of the given numbered (one-based) word.
      Parameters:
      inString - The string to search.
      wordNumber - The number (one-based) of the token to find.
      Returns:
      The index of the specified word, or -1 if that word was not found.
    • wordEndIndex

      public static int wordEndIndex(String inString, int wordNumber)
      Returns the index right after the given numbered (one-based) word.
      Parameters:
      inString - The string to search.
      wordNumber - The number (one-based) of the word to find.
      Returns:
      The index of one character past the last character of the specified word number, or -1 if that word was not found.
    • stringWord

      public static String stringWord(String inString, int wordNumber)
      Returns the specified numbered (one-based) word in the specified string.
      Parameters:
      inString - The string to search.
      wordNumber - The number (one-based) of the word to find.
      Returns:
      The specified numbered (one-based) word in the specified string, or "" if that word was not found.
    • getWordBeginning

      public static int getWordBeginning(String inString, int index)
      Returns the beginning of the word at index. If the character at index is whitespace, the beginning of the previous word will be returned.
      Parameters:
      inString - The string with the word.
      index - The index of the character in a word.
      Returns:
      The index of the beginning character of the word.
    • getWordEnd

      public static int getWordEnd(String inString, int index)
      Returns the end of the word at index. If the character at index is whitespace, the end of the next word will be returned.
      Parameters:
      inString - The string with the word.
      index - The index of the character in a word.
      Returns:
      The index of the ending character of the word.
    • makeHTMLHyperlinks

      public static String makeHTMLHyperlinks(String inString)
      Parses the string and finds any hyperlinks, to which it then creates and inserts the appropriate HTML tags.
      Parameters:
      inString - The string in which to find hyperlinks.
      Returns:
      A string with HTML hyperlink tags embedded.
    • createString

      public static String createString(char firstChar, char lastChar)
      Creates a string containing a range of characters.
      Parameters:
      firstChar - The character to start with.
      lastChar - The last character to include, which should have a value higher than or equal to firstChar.
      Returns:
      A string containing a range of characters including the first and last characters provided.
    • createString

      public static String createString(char ch, int count)
      Creates a string with a given repetition of characters.
      Parameters:
      ch - The character to be in the string.
      count - The number of repetitions of the character.
      Returns:
      A string with count repetitions of ch.
    • makeStringLength

      @Deprecated public static String makeStringLength(String inString, int len, char ch)
      Deprecated.
      to be removed in favor of forceLength(String, int, char).
      Ensures that the given string is the correct length by adding or deleting characters to or from the end.
      Parameters:
      inString - The string to process.
      len - The requested length.
      ch - The character to be added to the string, if needed.
      Returns:
      A string with the correct length.
    • forceLength

      public static String forceLength(String inString, int len, char ch)
      Ensures that the given string is the correct length by adding or deleting characters to or from the end.
      Parameters:
      inString - The string to process.
      len - The requested length.
      ch - The character to be added to the string, if needed.
      Returns:
      A string with the correct length.
      See Also:
    • makeStringLength

      @Deprecated public static String makeStringLength(String inString, int len, char ch, int pos)
      Deprecated.
      to be removed in favor of forceLength(String, int, char, int).
      Ensures that the given string is the correct length by adding or deleting characters to or from the requested position.
      Parameters:
      inString - The string to process.
      len - The requested length.
      ch - The character to be added to the string, if needed.
      pos - The position at which to insert or delete characters, or -1 if the end should be used.
      Returns:
      A string with the correct length.
    • forceLength

      public static String forceLength(String inString, int len, char ch, int pos)
      Ensures that the given string is the correct length by adding or deleting characters to or from the requested position.
      Parameters:
      inString - The string to process.
      len - The requested length.
      ch - The character to be added to the string, if needed.
      pos - The position at which to insert or delete characters, or -1 if the end should be used.
      Returns:
      A string with the correct length.
      See Also:
    • remove

      public static String remove(String inString, int index)
      Removes a character at the specified index.
      Parameters:
      inString - the String from which the information will be removed.
      index - The index of the information to remove.
      Returns:
      A new string with the specified information removed from the specified location.
    • remove

      public static String remove(String inString, int index, int len)
      Removes several characters at the specified index.
      Parameters:
      inString - the String from which the information will be removed.
      index - The index of the information to remove.
      len - The number of characters to remove.
      Returns:
      A new string with the specified information removed from the specified location.
    • removeAfterFirstChar

      public static String removeAfterFirstChar(String string, Characters delimiters)
      Removes all characters that come after and including the first occurrence of a character in the given delimiter string. If the character does not exist in the string, the original string will be returned.
      Parameters:
      string - The string to check.
      delimiters - The characters that indicate removal should occur.
      Returns:
      The string with the first matching character and everything after it removed, or the original string if no characters were in the supplied set of delimiters.
    • removeBeforeLast

      public static String removeBeforeLast(String string, char c)
      Removes all characters that come before the last occurrence of the given character. If the character does not exist in the string, the original string will be returned.
      Parameters:
      string - The string to be used to create a new string after the given character.
      c - The character used as a delimiter to be removed with all the content before it.
      Returns:
      The string without the characters before the given character.
    • removeLengthIgnoreCase

      public static String removeLengthIgnoreCase(String string, String substring)
      Removes the given substring, matched without case sensitivity, and everything following the string.
      Parameters:
      string - The string that may contain the substring.
      substring - The string to match without case sensitivity.
      Returns:
      The string with the substring and everything following it removed, or the original string if no changes were made.
    • trimBeginningFirst

      public static String trimBeginningFirst(String inString, char removeChar)
      Trims the left side of the string beginning at the first occurrence of removeChar. If removeChar does not exist in the string, no information is removed.
      Parameters:
      inString - the String from which the information will be removed. The occurrences are considered from the left to the right.
      removeChar - The character to remove from the string.
      Returns:
      A new string with its beginning removed.
    • trimBeginningLast

      public static String trimBeginningLast(String inString, char removeChar)
      Trims the left side of the string beginning at the last occurrence of removeChar. If removeChar does not exist in the string, no information is removed.
      Parameters:
      inString - the String from which the information will be removed. The occurrences are considered from the left to the right.
      removeChar - The character to remove from the string.
      Returns:
      A new string with its beginning removed.
    • trimBeginning

      public static String trimBeginning(String inString, char removeChar, int occurrence)
      Trims the left side of the string beginning at the specified occurrence of removeChar from the beginning. If removeChar does not exist in the string the required number of times, the string will be trimmed at the last occurrence. The occurrences are considered from the left to the right. If Integer.MAX_VALUE is provided, the last occurrence from the left to the right of remove char is used.
      Parameters:
      inString - the String from which the information will be removed.
      removeChar - The character to remove from the string.
      occurrence - The number of occurrences of the remove character before information should be removed.
      Returns:
      A new string with its end removed.
    • trimEndFirst

      public static String trimEndFirst(String inString, char removeChar)
      Trims the right side of the string beginning at the first occurrence of removeChar. If removeChar does not exist in the string, no information is removed.
      Parameters:
      inString - the String from which the information will be removed. The occurrences are considered from the right to the left.
      removeChar - The character to remove from the string.
      Returns:
      A new string with its end removed.
    • trimEndLast

      public static String trimEndLast(String inString, char removeChar)
      Trims the right side of the string beginning at the last occurrence of removeChar. If removeChar does not exist in the string, no information is removed.
      Parameters:
      inString - the String from which the information will be removed. The occurrences are considered from the right to the left.
      removeChar - The character to remove from the string.
      Returns:
      A new string with its end removed.
    • trimEnd

      public static String trimEnd(String inString, char removeChar, int occurrence)
      Trims the right side of the string beginning at the specified occurrence of removeChar from the end. If removeChar does not exist in the string the required number of times, the string will be trimmed at the last occurrence. The occurrences are considered from the right to the left. If Integer.MAX_VALUE is provided, the last occurrence from the right to the left of remove char is used.
      Parameters:
      inString - the String from which the information will be removed.
      removeChar - The character to remove from the string.
      occurrence - The number of occurrences of the remove character before information should be removed.
      Returns:
      A new string with its end removed.
    • replace

      public static String replace(String inString, int index, int len, String replaceString)
      Removes several characters at the specified index and replaces them with the given string.
      Parameters:
      inString - the String from which the information will be removed.
      index - The index of the information to remove.
      len - The number of characters to remove.
      replaceString - The string of characters to put in the place of the removed characters.
      Returns:
      A new string with the specified information removed from the specified location.
    • replace

      public static String replace(String inString, char replaceChar, String withString)
      Replaces every occurrence of a specified character with a string.
      Parameters:
      inString - the String from in the information will be replaced.
      replaceChar - The character to replace.
      withString - The string that will replace replaceChar.
      Returns:
      A new string with the specified information replaced.
    • replace

      public static String replace(String inString, String replaceString, String withString)
      Replaces every occurrence of a specified string with another string.
      Parameters:
      inString - the String from in the information will be replaced.
      replaceString - The string to replace.
      withString - The string that will replace replaceString.
      Returns:
      A new string with the specified information replaced.
    • replace

      public static String replace(String inString, Characters matchCharacters, char replacementChar)
      Replaces any of several matching characters with a particular character.
      Parameters:
      inString - The string in which characters should be replaced.
      matchCharacters - The string containing characters to be matched; every character that matches one of these characters will be replaced with the replacement character.
      replacementChar - The character to replace any matched character.
      Returns:
      A string with the appropriate characters replaced by the replacement character.
    • replace

      public static String replace(String inString, Characters matchCharacters, String replacementString)
      Replaces any of several matching characters with a particular string.
      Parameters:
      inString - The string in which characters should be replaced.
      matchCharacters - The string containing characters to be matched; every character that matches one of these characters will be replaced with the replacement string.
      replacementString - The string to replace any matched character.
      Returns:
      A string with the appropriate characters replaced by the replacement string.
    • replace

      public static String replace(String string, char[] matchChars, String[] replacementStrings)
      Replaces each matching character with the corresponding replacement string.
      Parameters:
      string - The string in which the replacements will be made.
      matchChars - An array of characters to be replaced.
      replacementStrings - An array of strings to replace the characters appearing at the same indexes as those in matchChars.
      Returns:
      The string with replacements made, which may be the original string if no replacements were made.
    • truncate

      public static String truncate(String string, int maxLength)
      Truncates the string, if needed, to ensure that the string is no longer than the provided length.
      Parameters:
      string - The string to truncate.
      maxLength - The maximum length of the string; if the string is longer than the given length, it will be truncated.
      Returns:
      The string, if the string was shorter than or equal to the maximum length; otherwise, the first maxLength characters of the string.
    • truncateChar

      public static String truncateChar(String string, Characters delimiters)
      Removes everything after and including the first occurrence of one of the given characters.
      Parameters:
      string - The string that may contain one or more of the characters.
      delimiters - The characters that will cause
      Returns:
      The string with the first occurring character and everything after it removed, or the original string if no changes were made.
    • collapse

      public static String collapse(String inString, Characters collapseChars, String replaceString)
      Collapses every run of any number of collapseChars to a single replacement string.
      Parameters:
      inString - the String in which the information will be collapsed.
      collapseChars - The characters to be removed from the string.
      replaceString - The string which will replace the collapseChars.
      Returns:
      A new string with the specified information collapsed.
    • trim

      public static String trim(String inString, Characters delimiters)
      Trims the specified delimiters from the beginning and end of the string.
      Parameters:
      inString - The string to be processed.
      delimiters - The string containing delimiter characters.
      Returns:
      The string without the delimiters from the beginning and end of the string.
    • trimWhitespaceNoBreak

      public static String trimWhitespaceNoBreak(String inString)
      Trims whitespace, including the Unicode no-break space character 0x00A0, from the beginning and end of the string.
      Parameters:
      inString - The string to be processed.
      Returns:
      The string without any whitespace on the beginning or the end of the string.
    • trimWhitespaceNoBreakBeginning

      public static String trimWhitespaceNoBreakBeginning(String inString)
      Trims whitespace, including the Unicode no-break space character 0x00A0, from the beginning of the string.
      Parameters:
      inString - The string to be processed.
      Returns:
      The string without any spaces on the beginning of the string.
    • trimWhitespaceNoBreakEnd

      public static String trimWhitespaceNoBreakEnd(String inString)
      Trims whitespace, including the Unicode no-break space character 0x00A0, from the beginning of the string.
      Parameters:
      inString - The string to be processed.
      Returns:
      The string without any spaces on the end of the string.
    • trimBeginning

      public static String trimBeginning(String inString, String beginString)
      If the input string begins with the specifid string, trims that string.
      Parameters:
      inString - The string to be processed.
      beginString - The string to be trimmed, if it appears at the beginning of inString.
      Returns:
      The string, trimmed if needed.
    • trimEnd

      public static String trimEnd(String inString, String endString)
      If the input string ends with the specified string, trims that string.
      Parameters:
      inString - The string to be processed.
      endString - The string to be trimmed, if it appears at the end of inString.
      Returns:
      The string, trimmed if needed.
    • wrap

      public static String wrap(String inString, int wrapLength)
      Performs word-wrapping on the input string by strategically inserting ends-of-line, ensuring that each line is no longer than the specified length.
      Parameters:
      inString - The string to be wrapped.
      wrapLength - The maximum length of any line.
      Returns:
      The string wrapped with the given characters inserted.
    • wrap

      public static String wrap(String inString, int wrapLength, char padChar, char eolChar)
      Performs word-wrapping on the input string by strategically inserting ends-of-line, ensuring that each line is no longer than the specified length.
      Parameters:
      inString - The string to be wrapped.
      wrapLength - The maximum length of any line.
      padChar - The character to use to pad each line, or UNDEFINED_CHAR if lines should not be padded.
      eolChar - The string to insert at the end of each line, or UNDEFINED_CHAR if ends of lines should not be marked.
      Returns:
      The string wrapped with the given characters inserted.
    • write

      public static <T> String write(URI baseURI, T object, IO<T> io) throws IOException
      Writes an object to a string using the given I/O support, converting bytes to a string using the UTF-8 charset.
      Type Parameters:
      T - The type of the object
      Parameters:
      baseURI - The base URI of the data, or null if no base URI is available.
      object - The object to write to a string.
      io - The I/O support for writing the object.
      Returns:
      The given object converted to a string.
      Throws:
      IOException - if there is an error writing the data.
    • write

      public static <T> String write(URI baseURI, T object, IO<T> io, Charset charset) throws IOException
      Writes an object to a string using the given I/O support.
      Type Parameters:
      T - The type of the object
      Parameters:
      baseURI - The base URI of the data, or null if no base URI is available.
      object - The object to write to a string.
      io - The I/O support for writing the object.
      charset - The encoding with which to interpret the written bytes.
      Returns:
      The given object converted to a string.
      Throws:
      IOException - if there is an error writing the data.