Class StringBuilders


  • public class StringBuilders
    extends java.lang.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:
    Strings
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder, char character, int count)
      Appends a given repetition of characters to a string builder.
      static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder, char delimiter, java.lang.CharSequence... charSequences)
      Concatenates the given character sequences by appending them to the string buffer, separated by the given delimiter.
      static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder, java.lang.CharSequence... charSequences)
      Concatenates the given character sequences by appending them to the string buffer.
      static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder, java.lang.Object... objects)
      Concatenates the string representations of the objects in the array by appending them to the string buffer.
      static java.lang.StringBuilder appendChar​(java.lang.StringBuilder stringBuilder, int c)
      Appends a character to a string builder.
      static java.lang.StringBuilder appendForceLength​(java.lang.StringBuilder stringBuilder, java.lang.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.
      static java.lang.StringBuilder appendForceLength​(java.lang.StringBuilder stringBuilder, java.lang.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.
      static java.lang.StringBuilder asStringBuilder​(java.lang.CharSequence charSequence)
      Returns a string builder version of the given characters sequence.
      static java.lang.StringBuilder clear​(java.lang.StringBuilder stringBuilder)
      Removes all the content of a string builder.
      static int collapse​(java.lang.StringBuilder stringBuilder, Characters collapseChars, java.lang.String replaceString)
      Collapses every run of any number of collapseChars to a single replaceString.
      static int collapse​(java.lang.StringBuilder stringBuilder, Characters collapseChars, java.lang.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​(java.lang.StringBuilder stringBuilder, Characters collapseChars, java.lang.String replaceString, int offset, int length)
      Collapses every run of any number of collapseChars to a single replaceString.
      static void deleteEnd​(java.lang.StringBuilder stringBuilder)
      Deletes the last character of a string builder.
      static void deleteEnd​(java.lang.StringBuilder stringBuilder, int count)
      Deletes the last characters of a string builder.
      static java.lang.String escapeHex​(java.lang.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 java.lang.String escapeHex​(java.lang.StringBuilder stringBuilder, int index, char escapeChar, int escapeLength)
      Escapes the indicated character in the string builder using the supplied escape character.
      static java.lang.String escapeHex​(java.lang.StringBuilder stringBuilder, int index, char escapeChar, int escapeLength, Case hexCase)
      Escapes the indicated character in the string builder using the supplied escape character.
      static java.lang.StringBuilder escapeHex​(java.lang.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.
      static java.lang.StringBuilder escapeHex​(java.lang.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.
      static java.lang.StringBuilder escapeHex​(java.lang.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​(java.lang.StringBuilder stringBuilder, char c)
      Returns the index of the first non-occurrence of the given character in the string buffer.
      static int indexNotOf​(java.lang.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​(java.lang.StringBuilder stringBuilder, char c)
      Returns the index of the first occurrence of the given character in the string buffer.
      static int indexOf​(java.lang.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.
      static java.lang.StringBuilder insert​(java.lang.StringBuilder stringBuilder, int offset, char character, int count)
      Inserts a given repetition of characters into a string builder.
      static java.lang.StringBuilder insert​(java.lang.StringBuilder stringBuilder, int offset, java.lang.CharSequence charSequence)
      Inserts a character sequence into a string builder.
      static int notCharIndexOf​(java.lang.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​(java.lang.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.
      static java.lang.StringBuilder removeEvery​(java.lang.StringBuilder stringBuilder, char removeChar)
      Removes every occurrence of a specified character.
      static java.lang.StringBuilder removeEveryChar​(java.lang.StringBuilder stringBuilder, java.lang.String removeChars)
      Removes every occurrence of any of the given specified characters.
      static java.lang.StringBuilder removeFirstCharLength​(java.lang.StringBuilder stringBuilder, Characters delimiters)
      Removes all content after and including the first occurrence of a character appearing in the delimiter string.
      static int replace​(java.lang.StringBuilder stringBuilder, char[] conversionTable)
      Converts all characters in the string buffer to corresponding characters in a given lookup table.
      static int replace​(java.lang.StringBuilder stringBuilder, char[][] matchReplaceSetArray)
      Replaces each matching character with a given replacement.
      static int replace​(java.lang.StringBuilder stringBuilder, char[] matchChars, java.lang.String[] replacementStrings)
      Replaces each matching character with the corresponding replacement string.
      static int replace​(java.lang.StringBuilder stringBuilder, char matchChar, char replacementChar)
      Replaces each matching character with the given replacement character.
      static int replace​(java.lang.StringBuilder stringBuilder, char matchChar, java.lang.String replacementString)
      Replaces each matching character with the given replacement string.
      static java.lang.StringBuilder replace​(java.lang.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​(java.lang.StringBuilder stringBuilder, Characters matchCharacters, char replacementChar)
      Replaces each matching character with the given replacement.
      static int replace​(java.lang.StringBuilder stringBuilder, Characters matchCharacters, java.lang.String replacementString)
      Replaces each matching character with the given replacement string.
      static int replace​(java.lang.StringBuilder stringBuilder, java.lang.String replaceString, java.lang.String withString)
      Replaces every occurrence of a specified string with another string.
      static java.lang.StringBuilder replaceRuns​(java.lang.StringBuilder stringBuilder, char matchChar, int minRunLength, int maxRunLength, char replaceChar)
      Replaces all runs of the given character with another character.
      static boolean startsWith​(java.lang.StringBuilder stringBuilder, java.lang.String string)
      Determines if the string buffer starts with the given string.
      static java.lang.StringBuilder trim​(java.lang.StringBuilder stringBuilder, Characters delimiters)
      Trims the specified delimiters from the beginning and end of the string buffer.
      static java.lang.StringBuilder trimBeginning​(java.lang.StringBuilder stringBuilder, Characters delimiters)
      Trims the specified delimiters from the beginning of the string buffer.
      static java.lang.StringBuilder trimEnd​(java.lang.StringBuilder stringBuilder, char delimiter)
      Trims the specified delimiter from the end of the string buffer.
      static java.lang.StringBuilder trimEnd​(java.lang.StringBuilder stringBuilder, Characters delimiters)
      Trims the specified delimiters from the end of the string buffer.
      static java.lang.StringBuilder unescape​(java.lang.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 Detail

      • append

        public static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder,
                                                     java.lang.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:
        StringBuilder.append(Object)
      • append

        public static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder,
                                                     java.lang.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:
        java.lang.NullPointerException - if the given character sequences is null.
      • append

        public static java.lang.StringBuilder append​(java.lang.StringBuilder stringBuilder,
                                                     char delimiter,
                                                     java.lang.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:
        java.lang.NullPointerException - if the given string builder and/or character sequences is null.
      • append

        public static java.lang.StringBuilder append​(java.lang.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 java.lang.StringBuilder asStringBuilder​(java.lang.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 java.lang.StringBuilder appendChar​(java.lang.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:
        java.lang.NullPointerException - if the given string builder is null.
      • clear

        public static java.lang.StringBuilder clear​(java.lang.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 java.lang.StringBuilder insert​(java.lang.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:
        java.lang.StringIndexOutOfBoundsException - if the index is negative or greater than the length.
      • insert

        public static java.lang.StringBuilder insert​(java.lang.StringBuilder stringBuilder,
                                                     int offset,
                                                     java.lang.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:
        java.lang.IndexOutOfBoundsException - if the given destination index is outside the bounds of the string builder.
        See Also:
        StringBuilder.insert(int, java.lang.CharSequence)
      • collapse

        public static int collapse​(java.lang.StringBuilder stringBuilder,
                                   Characters collapseChars,
                                   java.lang.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​(java.lang.StringBuilder stringBuilder,
                                   Characters collapseChars,
                                   java.lang.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​(java.lang.StringBuilder stringBuilder,
                                   Characters collapseChars,
                                   java.lang.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​(java.lang.StringBuilder stringBuilder)
        Deletes the last character of a string builder.
        Parameters:
        stringBuilder - The string builder to modify.
        Throws:
        java.lang.NullPointerException - if the given string builder is null.
        java.lang.StringIndexOutOfBoundsException - if the given string builder has no characters.
      • deleteEnd

        public static void deleteEnd​(java.lang.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:
        java.lang.IllegalArgumentException - if the given string builder has insufficient characters.
        java.lang.StringIndexOutOfBoundsException - if the given string builder is null.
      • escapeHex

        public static java.lang.StringBuilder escapeHex​(java.lang.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:
        java.lang.IllegalArgumentException - if neither valid nor invalid characters are given.
      • escapeHex

        public static java.lang.StringBuilder escapeHex​(java.lang.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:
        java.lang.IllegalArgumentException - if neither valid nor invalid characters are given.
      • escapeHex

        public static java.lang.StringBuilder escapeHex​(java.lang.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:
        java.lang.IllegalArgumentException - if neither valid nor invalid characters are given.
        java.lang.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 java.lang.String escapeHex​(java.lang.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:
        java.lang.StringIndexOutOfBoundsException - if the given index does not represent a valid location in the string builder.
      • escapeHex

        public static java.lang.String escapeHex​(java.lang.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:
        java.lang.StringIndexOutOfBoundsException - if the given index does not represent a valid location in the string builder.
      • escapeHex

        public static java.lang.String escapeHex​(java.lang.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:
        java.lang.StringIndexOutOfBoundsException - if the given index does not represent a valid location in the string builder.
        java.lang.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 java.lang.StringBuilder unescape​(java.lang.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:
        java.lang.NullPointerException - if the given string builder is null.
        java.lang.IllegalArgumentException - if the string builder ends with the given escape character.
      • appendForceLength

        public static java.lang.StringBuilder appendForceLength​(java.lang.StringBuilder stringBuilder,
                                                                java.lang.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 java.lang.StringBuilder appendForceLength​(java.lang.StringBuilder stringBuilder,
                                                                java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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 java.lang.StringBuilder removeFirstCharLength​(java.lang.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 java.lang.StringBuilder removeEvery​(java.lang.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 java.lang.StringBuilder removeEveryChar​(java.lang.StringBuilder stringBuilder,
                                                              java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.StringBuilder stringBuilder,
                                  char matchChar,
                                  java.lang.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​(java.lang.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​(java.lang.StringBuilder stringBuilder,
                                  Characters matchCharacters,
                                  java.lang.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​(java.lang.StringBuilder stringBuilder,
                                  char[] matchChars,
                                  java.lang.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​(java.lang.StringBuilder stringBuilder,
                                  java.lang.String replaceString,
                                  java.lang.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 java.lang.StringBuilder replaceRuns​(java.lang.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 java.lang.StringBuilder replace​(java.lang.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:
        StringBuilder.replace(int, int, java.lang.String)
      • startsWith

        public static boolean startsWith​(java.lang.StringBuilder stringBuilder,
                                         java.lang.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 java.lang.StringBuilder trim​(java.lang.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 java.lang.StringBuilder trimBeginning​(java.lang.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 java.lang.StringBuilder trimEnd​(java.lang.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 java.lang.StringBuilder trimEnd​(java.lang.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.