Class StringBuilders

java.lang.Object
com.globalmentor.java.StringBuilders

public class StringBuilders extends Object
Various methods that manipulate StringBuilder objects. These methods are fast relative to their Strings counterparts, because the StringBuilder objects on which they operate can be modified within the object instead of forcing a new object to be created. These methods furthermore modify the specified StringBuilder object rather than returning a new object.
Author:
Garret Wilson
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    append(StringBuilder stringBuilder, char character, int count)
    Appends a given repetition of characters to a string builder.
    append(StringBuilder stringBuilder, char delimiter, CharSequence... charSequences)
    Concatenates the given character sequences by appending them to the string buffer, separated by the given delimiter.
    append(StringBuilder stringBuilder, CharSequence... charSequences)
    Concatenates the given character sequences by appending them to the string buffer.
    append(StringBuilder stringBuilder, Object... objects)
    Concatenates the string representations of the objects in the array by appending them to the string buffer.
    appendChar(StringBuilder stringBuilder, int c)
    Appends a character to a string builder.
    appendForceLength(StringBuilder stringBuilder, CharSequence charSequence, int forceLength, char character)
    Appends a character sequence, ensuring that the given character sequence is the correct length by adding or deleting characters to or from the end.
    appendForceLength(StringBuilder stringBuilder, CharSequence charSequence, int forceLength, char character, int position)
    Appends a character sequence, ensuring that the given character sequence is the correct length by adding or deleting characters to or from the given position.
    Returns a string builder version of the given characters sequence.
    clear(StringBuilder stringBuilder)
    Removes all the content of a string builder.
    static int
    collapse(StringBuilder stringBuilder, Characters collapseChars, String replaceString)
    Collapses every run of any number of collapseChars to a single replaceString.
    static int
    collapse(StringBuilder stringBuilder, Characters collapseChars, String replaceString, int offset)
    Collapses every run of any number of collapseChars to a single replaceString, starting with the given offset and collapsing until the end of the string
    static int
    collapse(StringBuilder stringBuilder, Characters collapseChars, String replaceString, int offset, int length)
    Collapses every run of any number of collapseChars to a single replaceString.
    static void
    deleteEnd(StringBuilder stringBuilder)
    Deletes the last character of a string builder.
    static void
    deleteEnd(StringBuilder stringBuilder, int count)
    Deletes the last characters of a string builder.
    escape(StringBuilder stringBuilder, Characters restricted, char escape)
    Escapes a given string builder by inserting an escape character before every restricted character, including any occurrence of the given escape character.
    escape(StringBuilder stringBuilder, Characters restricted, char escape, boolean escapeEscape)
    Escapes a given string builder by inserting an escape character before every restricted character, optionally including any occurrence of the given escape character.
    static String
    escapeHex(StringBuilder stringBuilder, int index, char c, char escapeChar, int escapeLength, Case hexCase)
    Escapes the indicated character in the string builder using the supplied escape character.
    static String
    escapeHex(StringBuilder stringBuilder, int index, char escapeChar, int escapeLength)
    Escapes the indicated character in the string builder using the supplied escape character.
    static String
    escapeHex(StringBuilder stringBuilder, int index, char escapeChar, int escapeLength, Case hexCase)
    Escapes the indicated character in the string builder using the supplied escape character.
    escapeHex(StringBuilder stringBuilder, int start, int end, Characters validCharacters, Characters invalidCharacters, int maxCharacter, char escapeChar, int escapeLength, Case hexCase)
    Escapes the indicated characters in the string builder using the supplied escape character.
    escapeHex(StringBuilder stringBuilder, int start, Characters validCharacters, Characters invalidCharacters, int maxCharacter, char escapeChar, int escapeLength, Case hexCase)
    Escapes the indicated characters in the string builder using the supplied escape character.
    escapeHex(StringBuilder stringBuilder, Characters validCharacters, Characters invalidCharacters, int maxCharacter, char escapeChar, int escapeLength, Case hexCase)
    Escapes the indicated characters in the string builder using the supplied escape character.
    static int
    indexNotOf(StringBuilder stringBuilder, char c)
    Returns the index of the first non-occurrence of the given character in the string buffer.
    static int
    indexNotOf(StringBuilder stringBuilder, char c, int fromIndex)
    Returns the index of the first non-occurrence of the given character in the string buffer from the given index.
    static int
    indexOf(StringBuilder stringBuilder, char c)
    Returns the index of the first occurrence of the given character in the string buffer.
    static int
    indexOf(StringBuilder stringBuilder, char c, int fromIndex)
    Returns the index of the first occurrence of the given character in the string buffer from the given index.
    insert(StringBuilder stringBuilder, int offset, char character, int count)
    Inserts a given repetition of characters into a string builder.
    insert(StringBuilder stringBuilder, int offset, CharSequence charSequence)
    Inserts a character sequence into a string builder.
    static int
    notCharIndexOf(StringBuilder stringBuilder, Characters notCharCharacters)
    Searches a string buffer and returns the first index of any character not in the specified characters, starting from the beginning.
    static int
    notCharIndexOf(StringBuilder stringBuilder, Characters notCharacters, int fromIndex)
    Searches a string buffer and returns the first index of any character not in the specified characters, starting at fromIndex.
    removeEvery(StringBuilder stringBuilder, char removeChar)
    Removes every occurrence of a specified character.
    removeEveryChar(StringBuilder stringBuilder, String removeChars)
    Removes every occurrence of any of the given specified characters.
    removeFirstCharLength(StringBuilder stringBuilder, Characters delimiters)
    Removes all content after and including the first occurrence of a character appearing in the delimiter string.
    static int
    replace(StringBuilder stringBuilder, char[] conversionTable)
    Converts all characters in the string buffer to corresponding characters in a given lookup table.
    static int
    replace(StringBuilder stringBuilder, char[][] matchReplaceSetArray)
    Replaces each matching character with a given replacement.
    static int
    replace(StringBuilder stringBuilder, char[] matchChars, String[] replacementStrings)
    Replaces each matching character with the corresponding replacement string.
    static int
    replace(StringBuilder stringBuilder, char matchChar, char replacementChar)
    Replaces each matching character with the given replacement character.
    static int
    replace(StringBuilder stringBuilder, char matchChar, String replacementString)
    Replaces each matching character with the given replacement string.
    replace(StringBuilder stringBuilder, int startIndex, int endIndex, char replaceChar)
    Removes several characters at the specified index and replaces them with the given character.
    static int
    replace(StringBuilder stringBuilder, Characters matchCharacters, char replacementChar)
    Replaces each matching character with the given replacement.
    static int
    replace(StringBuilder stringBuilder, Characters matchCharacters, String replacementString)
    Replaces each matching character with the given replacement string.
    static int
    replace(StringBuilder stringBuilder, String replaceString, String withString)
    Replaces every occurrence of a specified string with another string.
    replaceRuns(StringBuilder stringBuilder, char matchChar, int minRunLength, int maxRunLength, char replaceChar)
    Replaces all runs of the given character with another character.
    static boolean
    startsWith(StringBuilder stringBuilder, String string)
    Determines if the string buffer starts with the given string.
    trim(StringBuilder stringBuilder, Characters delimiters)
    Trims the specified delimiters from the beginning and end of the string buffer.
    trimBeginning(StringBuilder stringBuilder, Characters delimiters)
    Trims the specified delimiters from the beginning of the string buffer.
    trimEnd(StringBuilder stringBuilder, char delimiter)
    Trims the specified delimiter from the end of the string buffer.
    trimEnd(StringBuilder stringBuilder, Characters delimiters)
    Trims the specified delimiters from the end of the string buffer.
    unescape(StringBuilder stringBuilder, char escapeChar)
    Unescapes a value int a string builder using the provided escape character.

    Methods inherited from class java.lang.Object

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

    • append

      public static StringBuilder append(StringBuilder stringBuilder, Object... objects)
      Concatenates the string representations of the objects in the array by appending them to the string buffer. Null objects are handled as per StringBuilder.append(Object).
      Parameters:
      stringBuilder - The string builder which the result should be placed.
      objects - The array of objects (such as strings) to be concatenated.
      Returns:
      The string builder containing the new information.
      See Also:
    • append

      public static StringBuilder append(StringBuilder stringBuilder, CharSequence... charSequences)
      Concatenates the given character sequences by appending them to the string buffer.
      Parameters:
      stringBuilder - The string builder which the result should be placed.
      charSequences - The character sequences to be appended.
      Returns:
      The string builder containing the new information.
      Throws:
      NullPointerException - if the given character sequences is null.
    • append

      public static StringBuilder append(StringBuilder stringBuilder, char delimiter, CharSequence... charSequences)
      Concatenates the given character sequences by appending them to the string buffer, separated by the given delimiter.
      Parameters:
      stringBuilder - The string builder which the result should be placed.
      delimiter - The delimiter to be placed between each character sequence, or Characters.UNDEFINED_CHAR if no delimiter should be placed between the character sequences.
      charSequences - The character sequences to be appended.
      Returns:
      The string builder containing the new information.
      Throws:
      NullPointerException - if the given string builder and/or character sequences is null.
    • append

      public static StringBuilder append(StringBuilder stringBuilder, char character, int count)
      Appends a given repetition of characters to a string builder.
      Parameters:
      stringBuilder - The string builder to which the characters should be appended.
      character - The character to append.
      count - The number of repetitions of the character.
      Returns:
      The string builder with the appended repetitions of the character.
    • asStringBuilder

      public static StringBuilder asStringBuilder(CharSequence charSequence)
      Returns a string builder version of the given characters sequence. If the given character sequence is already a string builder, it is returned; otherwise, a new string builder will be created from the contents of the character sequence.
      Parameters:
      charSequence - The character sequence for which a string builder should be returned.
      Returns:
      A string builder with the contents of the given character sequence.
    • appendChar

      public static StringBuilder appendChar(StringBuilder stringBuilder, int c)
      Appends a character to a string builder. This method supports Unicode supplementary code points.
      Parameters:
      stringBuilder - The string builder to which to append.
      c - The character to append.
      Returns:
      The string builder.
      Throws:
      NullPointerException - if the given string builder is null.
    • clear

      public static StringBuilder clear(StringBuilder stringBuilder)
      Removes all the content of a string builder.
      Parameters:
      stringBuilder - The string builder the content of which should be cleared.
      Returns:
      The string builder after all content is removed.
    • insert

      public static StringBuilder insert(StringBuilder stringBuilder, int offset, char character, int count)
      Inserts a given repetition of characters into a string builder.
      Parameters:
      stringBuilder - The string builder into which the characters should be inserted.
      offset - The index at which to insert the characters.
      character - The character to append.
      count - The number of repetitions of the character.
      Returns:
      The string builder with the inserted repetitions of the character.
      Throws:
      StringIndexOutOfBoundsException - if the index is negative or greater than the length.
    • insert

      public static StringBuilder insert(StringBuilder stringBuilder, int offset, CharSequence charSequence)
      Inserts a character sequence into a string builder. This method offers identical functionality to JDK 5.0 StringBuilder.insert(int, java.lang.CharSequence) and is provided here for backwards-compatibility using RetroWeaver, for example.
      Parameters:
      stringBuilder - The string builder into which the characters should be inserted.
      offset - The index at which to insert the characters.
      charSequence - The char sequence to be inserted on the string builder.
      Returns:
      The string builder after the insertion of the given char sequence.
      Throws:
      IndexOutOfBoundsException - if the given destination index is outside the bounds of the string builder.
      See Also:
    • collapse

      public static int collapse(StringBuilder stringBuilder, Characters collapseChars, String replaceString)
      Collapses every run of any number of collapseChars to a single replaceString.
      Parameters:
      stringBuilder - The buffer 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:
      The new length of the run with collapsed characters.
    • collapse

      public static int collapse(StringBuilder stringBuilder, Characters collapseChars, String replaceString, int offset)
      Collapses every run of any number of collapseChars to a single replaceString, starting with the given offset and collapsing until the end of the string
      Parameters:
      stringBuilder - The buffer in which the information will be collapsed.
      collapseChars - The characters to be removed from the string.
      replaceString - The string which will replace the collapseChars.
      offset - The offset at which to start collapsing.
      Returns:
      The new length of the run with collapsed characters.
    • collapse

      public static int collapse(StringBuilder stringBuilder, Characters collapseChars, String replaceString, int offset, int length)
      Collapses every run of any number of collapseChars to a single replaceString.
      Parameters:
      stringBuilder - The buffer in which the information will be collapsed.
      collapseChars - The characters to be removed from the string.
      replaceString - The string which will replace the collapseChars.
      offset - The offset at which to start collapsing.
      length - The length of the run of characters to check.
      Returns:
      The new length of the run with collapsed characters.
    • deleteEnd

      public static void deleteEnd(StringBuilder stringBuilder)
      Deletes the last character of a string builder.
      Parameters:
      stringBuilder - The string builder to modify.
      Throws:
      NullPointerException - if the given string builder is null.
      StringIndexOutOfBoundsException - if the given string builder has no characters.
    • deleteEnd

      public static void deleteEnd(StringBuilder stringBuilder, int count)
      Deletes the last characters of a string builder.
      Parameters:
      stringBuilder - The string builder to modify.
      count - The number of characters to delete.
      Throws:
      IllegalArgumentException - if the given string builder has insufficient characters.
      StringIndexOutOfBoundsException - if the given string builder is null.
    • escape

      public static StringBuilder escape(StringBuilder stringBuilder, Characters restricted, char escape)
      Escapes a given string builder by inserting an escape character before every restricted character, including any occurrence of the given escape character.
      Implementation Specification:
      This implementation delegates to escape(StringBuilder, Characters, char, boolean).
      Parameters:
      stringBuilder - The data to escape.
      restricted - The characters to be escaped; should not include the escape character.
      escape - The character used to escape the restricted characters.
      Returns:
      A string containing the escaped data.
      Throws:
      NullPointerException - if the given string builder is null.
    • escape

      public static StringBuilder escape(StringBuilder stringBuilder, Characters restricted, char escape, boolean escapeEscape)
      Escapes a given string builder by inserting an escape character before every restricted character, optionally including any occurrence of the given escape character.
      Parameters:
      stringBuilder - The data to escape.
      restricted - The characters to be escaped; should not include the escape character.
      escape - The character used to escape the restricted characters.
      escapeEscape - true if the escape character should also be escaped.
      Returns:
      A string containing the escaped data.
      Throws:
      NullPointerException - if the given string builder is null.
    • escapeHex

      public static StringBuilder escapeHex(StringBuilder stringBuilder, Characters validCharacters, Characters invalidCharacters, int maxCharacter, char escapeChar, int escapeLength, Case hexCase)
      Escapes the indicated characters in the string builder using the supplied escape character. All characters are first encoded using UTF-8. Every invalid character is converted to its Unicode hex equivalent and prefixed with the given escape character. Characters are assumed to be valid unless specified otherwise. The escape character, if encountered, is not escaped unless it specifically meets one of the specified criteria; this allows re-escaping strings that may contain escape characters produced under less-strict rules (e.g. a URI containing escaped restricted characters, but still containing non-ASCII characters).
      Parameters:
      stringBuilder - The data to escape.
      validCharacters - The characters that should not be escaped and all others should be escaped, or null if characters should not be matched against valid characters.
      invalidCharacters - The characters that, if they appear, should be escaped, or null if characters should not be matched against invalid characters.
      maxCharacter - The character value that represents the highest non-escaped value.
      escapeChar - The character to prefix the hex representation.
      escapeLength - The number of characters to use for the hex representation.
      hexCase - Whether the hex characters should be lowercase or uppercase.
      Returns:
      The string builder, now containing the escaped data.
      Throws:
      IllegalArgumentException - if neither valid nor invalid characters are given.
    • escapeHex

      public static StringBuilder escapeHex(StringBuilder stringBuilder, int start, Characters validCharacters, Characters invalidCharacters, int maxCharacter, char escapeChar, int escapeLength, Case hexCase)
      Escapes the indicated characters in the string builder using the supplied escape character. All characters are first encoded using UTF-8. Every invalid character is converted to its Unicode hex equivalent and prefixed with the given escape character. Characters are assumed to be valid unless specified otherwise. The escape character, if encountered, is not escaped unless it specifically meets one of the specified criteria; this allows re-escaping strings that may contain escape characters produced under less-strict rules (e.g. a URI containing escaped restricted characters, but still containing non-ASCII characters).
      Parameters:
      stringBuilder - The data to escape.
      start - The starting index to escape, inclusive; escaping will continue to the end of the string.
      validCharacters - The characters that should not be escaped and all others should be escaped, or null if characters should not be matched against valid characters.
      invalidCharacters - The characters that, if they appear, should be escaped, or null if characters should not be matched against invalid characters.
      maxCharacter - The character value that represents the highest non-escaped value.
      escapeChar - The character to prefix the hex representation.
      escapeLength - The number of characters to use for the hex representation.
      hexCase - Whether the hex characters should be lowercase or uppercase.
      Returns:
      The string builder, now containing the escaped data.
      Throws:
      IllegalArgumentException - if neither valid nor invalid characters are given.
    • escapeHex

      public static StringBuilder escapeHex(StringBuilder stringBuilder, int start, int end, Characters validCharacters, Characters invalidCharacters, int maxCharacter, char escapeChar, int escapeLength, Case hexCase)
      Escapes the indicated characters in the string builder using the supplied escape character. All characters are first encoded using UTF-8. Every invalid character is converted to its Unicode hex equivalent and prefixed with the given escape character. Characters are assumed to be valid unless specified otherwise. The escape character, if encountered, is not escaped unless it specifically meets one of the specified criteria; this allows re-escaping strings that may contain escape characters produced under less-strict rules (e.g. a URI containing escaped restricted characters, but still containing non-ASCII characters).

      If the char indicated at the given index is a half of a surrogate pair, then this implementation will escape both chars together.

      Parameters:
      stringBuilder - The data to escape.
      start - The starting index to escape, inclusive.
      end - The ending index to escape, exclusive.
      validCharacters - The characters that should not be escaped and all others should be escaped, or null if characters should not be matched against valid characters.
      invalidCharacters - The characters that, if they appear, should be escaped, or null if characters should not be matched against invalid characters.
      maxCharacter - The character value that represents the highest non-escaped value.
      escapeChar - The character to prefix the hex representation.
      escapeLength - The number of characters to use for the hex representation.
      hexCase - Whether the hex characters should be lowercase or uppercase.
      Returns:
      The string builder, now containing the escaped data.
      Throws:
      IllegalArgumentException - if neither valid nor invalid characters are given.
      IllegalStateException - if the given char is a high or low surrogate that does not have its pair completed (i.e. high surrogate + low surrogate).
    • escapeHex

      public static String escapeHex(StringBuilder stringBuilder, int index, char escapeChar, int escapeLength)
      Escapes the indicated character in the string builder using the supplied escape character. All characters are first encoded using UTF-8. The character is converted to its Unicode hex equivalent and prefixed with the given escape character. This method uses lowercase hexadecimal escape codes.
      Parameters:
      stringBuilder - The string builder containing data to escape.
      index - The index of the character to escape.
      escapeChar - The character to prefix the hex representation.
      escapeLength - The number of characters to use for the hex representation.
      Returns:
      A string representing the escaped data that was used as a replacement for the character.
      Throws:
      StringIndexOutOfBoundsException - if the given index does not represent a valid location in the string builder.
    • escapeHex

      public static String escapeHex(StringBuilder stringBuilder, int index, char escapeChar, int escapeLength, Case hexCase)
      Escapes the indicated character in the string builder using the supplied escape character. All characters are first encoded using UTF-8. The character is converted to its Unicode hex equivalent and prefixed with the given escape character.
      Parameters:
      stringBuilder - The string builder containing data to escape.
      index - The index of the character to escape.
      escapeChar - The character to prefix the hex representation.
      escapeLength - The number of characters to use for the hex representation.
      hexCase - Whether the hex characters should be lowercase or uppercase.
      Returns:
      A string representing the escaped data that was used as a replacement for the character.
      Throws:
      StringIndexOutOfBoundsException - if the given index does not represent a valid location in the string builder.
    • escapeHex

      public static String escapeHex(StringBuilder stringBuilder, int index, char c, char escapeChar, int escapeLength, Case hexCase)
      Escapes the indicated character in the string builder using the supplied escape character. All characters are first encoded using UTF-8. The character is converted to its Unicode hex equivalent and prefixed with the given escape character.

      If the char indicated at the given index is a half of a surrogate pair, then this implementation will escape both chars together.

      Parameters:
      stringBuilder - The string builder containing data to escape.
      index - The index of the character to replace.
      c - The character to be escaped.
      escapeChar - The character to prefix the hex representation.
      escapeLength - The number of characters to use for the hex representation.
      hexCase - Whether the hex characters should be lowercase or uppercase.
      Returns:
      A string representing the escaped data that was used as a replacement for the character.
      Throws:
      StringIndexOutOfBoundsException - if the given index does not represent a valid location in the string builder.
      IllegalStateException - if the given char is a high or low surrogate that does not have its pair completed (i.e. high surrogate + low surrogate).
    • unescape

      public static StringBuilder unescape(StringBuilder stringBuilder, char escapeChar)
      Unescapes a value int a string builder using the provided escape character. Every instance of the escape character will be removed if followed by another character and the subsequent character will be ignored.
      Parameters:
      stringBuilder - The string builder to unescape.
      escapeChar - The character to prefix the hex representation.
      Returns:
      The string builder with the unescaped content.
      Throws:
      NullPointerException - if the given string builder is null.
      IllegalArgumentException - if the string builder ends with the given escape character.
    • appendForceLength

      public static StringBuilder appendForceLength(StringBuilder stringBuilder, CharSequence charSequence, int forceLength, char character)
      Appends a character sequence, ensuring that the given character sequence is the correct length by adding or deleting characters to or from the end.
      Parameters:
      stringBuilder - The string builder to which the character sequence should be added.
      charSequence - The character sequence to add.
      forceLength - The requested length.
      character - The character to be added to the character sequence, if needed.
      Returns:
      A character sequence that is the requested number of characters longer.
    • appendForceLength

      public static StringBuilder appendForceLength(StringBuilder stringBuilder, CharSequence charSequence, int forceLength, char character, int position)
      Appends a character sequence, ensuring that the given character sequence is the correct length by adding or deleting characters to or from the given position.
      Parameters:
      stringBuilder - The string builder to which the character sequence should be added.
      charSequence - The character sequence to add.
      forceLength - The requested length.
      character - The character to be added to the character sequence, if needed.
      position - The position at which to insert or delete characters, or -1 if the end should be used.
      Returns:
      A character sequence that is the requested number of characters longer.
    • indexOf

      public static int indexOf(StringBuilder stringBuilder, char c)
      Returns the index of the first occurrence of the given character in the string buffer.
      Parameters:
      stringBuilder - The string buffer to search.
      c - The character to look for.
      Returns:
      The index in the string buffer of the given character, or -1 if no occurrence was found.
    • indexOf

      public static int indexOf(StringBuilder stringBuilder, char c, int fromIndex)
      Returns the index of the first occurrence of the given character in the string buffer from the given index.
      Parameters:
      stringBuilder - The string buffer to search.
      c - The character to look for.
      fromIndex - The index at which to start the search.
      Returns:
      The index in the string buffer of the given character, or -1 if no occurrence was found.
    • notCharIndexOf

      public static int notCharIndexOf(StringBuilder stringBuilder, Characters notCharCharacters)
      Searches a string buffer and returns the first index of any character not in the specified characters, starting from the beginning.
      Parameters:
      stringBuilder - The string buffer to be searched.
      notCharCharacters - The characters to check.
      Returns:
      The index of the first occurrence of one of the supplied characters, or -1 if none were found.
    • indexNotOf

      public static int indexNotOf(StringBuilder stringBuilder, char c)
      Returns the index of the first non-occurrence of the given character in the string buffer.
      Parameters:
      stringBuilder - The string buffer to search.
      c - The character to look for.
      Returns:
      The index in the string buffer of anything but the given character, or -1 if no non-occurrence was found.
    • indexNotOf

      public static int indexNotOf(StringBuilder stringBuilder, char c, int fromIndex)
      Returns the index of the first non-occurrence of the given character in the string buffer from the given index.
      Parameters:
      stringBuilder - The string buffer to search.
      c - The character to look for.
      fromIndex - The index at which to start the search.
      Returns:
      The index in the string buffer of anything but the given character, or -1 if no non-occurrence was found.
    • notCharIndexOf

      public static int notCharIndexOf(StringBuilder stringBuilder, Characters notCharacters, int fromIndex)
      Searches a string buffer and returns the first index of any character not in the specified characters, starting at fromIndex.
      Parameters:
      stringBuilder - The string buffer to be searched.
      notCharacters - The characters to check.
      fromIndex - The index to search from
      Returns:
      The index of the first occurrence of one of the supplied characters, or -1 if none were found.
    • removeFirstCharLength

      public static StringBuilder removeFirstCharLength(StringBuilder stringBuilder, Characters delimiters)
      Removes all content after and including the first occurrence of a character appearing in the delimiter string.
      Parameters:
      stringBuilder - The characters to examine.
      delimiters - The characters to search for.
      Returns:
      The string buffer after removal.
    • removeEvery

      public static StringBuilder removeEvery(StringBuilder stringBuilder, char removeChar)
      Removes every occurrence of a specified character.
      Parameters:
      stringBuilder - The string buffer from which the information will be removed.
      removeChar - The character to remove from the string buffer.
      Returns:
      The string buffer after removal.
    • removeEveryChar

      public static StringBuilder removeEveryChar(StringBuilder stringBuilder, String removeChars)
      Removes every occurrence of any of the given specified characters.
      Parameters:
      stringBuilder - The string buffer from which the information will be removed.
      removeChars - The characters to be removed from the string buffer.
      Returns:
      The string buffer after removal.
    • replace

      public static int replace(StringBuilder stringBuilder, char[] conversionTable)
      Converts all characters in the string buffer to corresponding characters in a given lookup table. Any characters not in the table will remain unchanged.
      Parameters:
      stringBuilder - The string buffer in which characters should be replaced.
      conversionTable - A map of replacement characters each stored at the index of the matching chararacter (e.g. character code x will be replaced by characterTable[x]).
      Returns:
      The number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, char[][] matchReplaceSetArray)
      Replaces each matching character with a given replacement.
      Parameters:
      stringBuilder - The buffer in which the replacements will be made.
      matchReplaceSetArray - An array of two-character arrays, each of the latter representing a set of characters, the first being a match character and the second a replacement character.
      Returns:
      The number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, char matchChar, char replacementChar)
      Replaces each matching character with the given replacement character.
      Parameters:
      stringBuilder - The buffer in which the replacements will be made.
      matchChar - The character to be replaced.
      replacementChar - The character for replacing the match character.
      Returns:
      The number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, char matchChar, String replacementString)
      Replaces each matching character with the given replacement string.
      Parameters:
      stringBuilder - The buffer in which the replacements will be made.
      matchChar - The character to be replaced.
      replacementString - The string for replacing the match character.
      Returns:
      The number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, Characters matchCharacters, char replacementChar)
      Replaces each matching character with the given replacement.
      Parameters:
      stringBuilder - The buffer in which the replacements will be made.
      matchCharacters - The characters, each of which will to be replaced.
      replacementChar - The character for replacing the match characters.
      Returns:
      The number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, Characters matchCharacters, String replacementString)
      Replaces each matching character with the given replacement string.
      Parameters:
      stringBuilder - The buffer in which the replacements will be made.
      matchCharacters - The characters, each of which will to be replaced.
      replacementString - The string for replacing the match characters.
      Returns:
      The number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, char[] matchChars, String[] replacementStrings)
      Replaces each matching character with the corresponding replacement string.
      Parameters:
      stringBuilder - The buffer 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 number of replacements made.
    • replace

      public static int replace(StringBuilder stringBuilder, String replaceString, String withString)
      Replaces every occurrence of a specified string with another string.
      Parameters:
      stringBuilder - The string buffer in which the information will be replaced.
      replaceString - The string to replace.
      withString - The string that will replace replaceString.
      Returns:
      The number of replacements made.
    • replaceRuns

      public static StringBuilder replaceRuns(StringBuilder stringBuilder, char matchChar, int minRunLength, int maxRunLength, char replaceChar)
      Replaces all runs of the given character with another character. A run is subsequent repeated characters. If a run is shorter than minRunLength or longer than maxRunLength, it will be ignored.
      Parameters:
      stringBuilder - The string buffer to search.
      matchChar - The char runs of which to replace.
      minRunLength - The minimum number of subsequent characters before replacement.
      maxRunLength - The maximum number of subsequent characters before replacement.
      replaceChar - The character that will replace all matching runs.
      Returns:
      The string buffer with all matching character runs replaced.
    • replace

      public static StringBuilder replace(StringBuilder stringBuilder, int startIndex, int endIndex, char replaceChar)
      Removes several characters at the specified index and replaces them with the given character. This duplicates StringBuilder.replace functionality without the overhead of a string.
      Parameters:
      stringBuilder - The buffer in which the information will be replaced.
      startIndex - The index of the information to remove.
      endIndex - One character past the last of the information to remove; must be greater than startIndex.
      replaceChar - The character to replace the removed characters.
      Returns:
      The string buffer with the specified contents replaced.
      See Also:
    • startsWith

      public static boolean startsWith(StringBuilder stringBuilder, String string)
      Determines if the string buffer starts with the given string.
      Parameters:
      stringBuilder - The string buffer to examine.
      string - The string to compare.
      Returns:
      true if the first characters of the string buffer match those of the given string.
    • trim

      public static StringBuilder trim(StringBuilder stringBuilder, Characters delimiters)
      Trims the specified delimiters from the beginning and end of the string buffer.
      Parameters:
      stringBuilder - The characters to be processed.
      delimiters - The delimiter characters.
      Returns:
      The trimmed string buffer.
    • trimBeginning

      public static StringBuilder trimBeginning(StringBuilder stringBuilder, Characters delimiters)
      Trims the specified delimiters from the beginning of the string buffer.
      Parameters:
      stringBuilder - The characters to be processed.
      delimiters - The delimiter characters.
      Returns:
      The trimmed string buffer.
    • trimEnd

      public static StringBuilder trimEnd(StringBuilder stringBuilder, char delimiter)
      Trims the specified delimiter from the end of the string buffer.
      Parameters:
      stringBuilder - The characters to be processed.
      delimiter - The delimiter character.
      Returns:
      The trimmed string buffer.
    • trimEnd

      public static StringBuilder trimEnd(StringBuilder stringBuilder, Characters delimiters)
      Trims the specified delimiters from the end of the string buffer.
      Parameters:
      stringBuilder - The characters to be processed.
      delimiters - The delimiter characters.
      Returns:
      The trimmed string buffer.