Package rife.tools

Class StringUtils

java.lang.Object
rife.tools.StringUtils

public final class StringUtils extends Object
General purpose class containing common String manipulation methods.
Since:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Pattern
     
    static final Pattern
     
    static final Pattern
     
    static final Pattern
     
    static final Pattern
     
    static final Pattern
     
    static final Pattern
     
    static Charset
     
    static String
     
    static String
     
    static String
     
    static String
     
    static String
     
    static String
     
    static String
     
    static String
     
    static final char[]
     
    static final char[]
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    appendHexDigit(StringBuilder out, int number)
    Appends the hexadecimal digit of the provided number.
    static void
    Appends the lowercase hexadecimal digit of the provided number.
    static String
    Ensure that the first character of the provided string is upper case.
    static String
    Converts a BBCode marked-up text to regular html.
    static String
    convertBbcode(String source, rife.tools.StringUtils.BbcodeOption... options)
    Converts a BBCode marked-up text to regular html.
    static String
    Replaces \n with the system line separator.
    static String
    convertTabsToSpaces(String line, int tabWidth)
    Converts all tabs on a line to spaces according to the provided tab width.
    static boolean
    Converts a String to a boolean value.
    static int
    count(String source, String substring)
    Counts the number of times a substring occures in a provided string in a case-sensitive manner.
    static int
    count(String source, String substring, boolean matchCase)
    Counts the number of times a substring occures in a provided string.
    static String
     
    static String
    decodeUrl(String source)
    Transforms a provided String URL into a new string, containing decoded URL characters in the UTF-8 encoding.
    static String
    encodeBase32(byte[] bytes)
    Encodes byte array to Base32 String.
    static String
    encodeBase64(byte[] bytes)
    Encodes byte array to Base64 String.
    static String
    Transforms a provided String object into a new string, containing only valid characters for a java class name.
    static String
    encodeHex(byte[] bytes)
    Generates an uppercase hexadecimal string for the provided byte array.
    static String
    encodeHexLower(byte[] bytes)
    Generates a lowercase hexadecimal string for the provided byte array.
    static String
    Transforms a provided String object into a new string, containing only valid Html characters.
    static String
    Transforms a provided String object into a new string, containing as much as possible Html characters.
    static String
    Transforms a provided String object into a new string, containing only valid Json characters.
    static String
    Transforms a provided String object into a new string, containing only valid LaTeX characters.
    static String
    Transforms a provided String object into a literal that can be included into a regular expression Pattern as-is.
    static String
    encodeSql(String source)
    Transforms a provided String object into a new string, containing only valid Sql characters.
    static String
    Transforms a provided String object into a new string, containing only valid String characters.
    static String
    Transforms a provided String object into a series of unicode escape codes.
    static String
    encodeUrl(String source)
    Transforms a provided String object into a new string, containing only valid URL characters in the UTF-8 encoding.
    static String
    encodeUrl(String source, char... allow)
    Transforms a provided String object into a new string, containing only valid URL characters in the UTF-8 encoding.
    static String
    encodeUrl(String source, String allow)
    Transforms a provided String object into a new string, containing only valid URL characters in the UTF-8 encoding.
    static String
    encodeXml(String source)
    Transforms a provided String object into a new string, containing only valid XML characters.
    static boolean
    filter(String name, List<Pattern> included, List<Pattern> excluded)
    Checks if the name filters through a series of including and excluding regular expressions.
    static boolean
    filter(String name, List<Pattern> included, List<Pattern> excluded, boolean matches)
    Checks if the name filters through a series of including and excluding regular expressions.
    static boolean
    filter(String name, Pattern[] included, Pattern[] excluded)
    Checks if the name filters through a series of including and excluding regular expressions.
    static boolean
    filter(String name, Pattern[] included, Pattern[] excluded, boolean matches)
    Checks if the name filters through a series of including and excluding regular expressions.
    static boolean
    filter(String name, Pattern included, Pattern excluded)
    Checks if the name filters through an including and an excluding regular expression.
    static boolean
    filter(String name, Pattern included, Pattern excluded, boolean matches)
    Checks if the name filters through an including and an excluding regular expression.
    getDocumentPosition(String document, int characterIndex)
    Calculates the DocumentPosition of a character index in a document.
    static Matcher
    Matches a collection of regular expressions against a string.
    static Matcher
    Matches a collection of strings against a regular expression.
    static int[]
    indicesOf(String source, String substring)
    Returns an array that contains all the occurances of a substring in a string in the correct order.
    static int[]
    indicesOf(String source, String substring, boolean matchCase)
    Returns an array that contains all the occurances of a substring in a string in the correct order.
    static String
    join(boolean[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(byte[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(char[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(char[] array, String separator, String delimiter)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(double[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(float[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(int[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(long[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(short[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(Object[] array, String separator)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(Object[] array, String separator, String delimiter)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(Object[] array, String separator, String delimiter, boolean encodeStrings)
    Creates a new String object, containing the elements of a supplied array, joined by a given separator.
    static String
    join(Collection<?> collection, String separator)
    Creates a new String object, containing the elements of a supplied Collection of String objects joined by a given separator.
    static String
    repeat(String source, int count)
    Creates a new string that contains the provided string a number of times.
    static String
    replace(String source, String stringToReplace, String replacementString)
    Searches for a string within a specified string in a case-sensitive manner and replaces every match with another string.
    static String
    replace(String source, String stringToReplace, String replacementString, boolean matchCase)
    Searches for a string within a specified string and replaces every match with another string.
    static List<String>
    split(String source, String separator)
    Splits a string into different parts, using a separator string to detect the seperation boundaries in a case-sensitive manner.
    static List<String>
    split(String source, String separator, boolean matchCase)
    Splits a string into different parts, using a separator string to detect the seperation boundaries.
    static String[]
    splitToArray(String source, String separator)
    Splits a string into different parts, using a separator string to detect the seperation boundaries in a case-sensitive manner.
    static String[]
    splitToArray(String source, String separator, boolean matchCase)
    Splits a string into different parts, using a separator string to detect the seperation boundaries.
    static byte[]
    splitToByteArray(String source, String separator)
    Splits a string into bytes, using a separator string to detect the seperation boundaries in a case-sensitive manner.
    static byte[]
    splitToByteArray(String source, String separator, boolean matchCase)
    Splits a string into bytes, using a separator string to detect the seperation boundaries.
    static int[]
    splitToIntArray(String source, String separator)
    Splits a string into integers, using a separator string to detect the seperation boundaries in a case-sensitive manner.
    static int[]
    splitToIntArray(String source, String separator, boolean matchCase)
    Splits a string into integers, using a separator string to detect the seperation boundaries.
    static String
    Removes all blank lines from text.
    static String
    stripFromEnd(String source, String stringToStrip)
    Removes all occurances of a string from the end of another string in a case-sensitive manner.
    static String
    stripFromEnd(String source, String stringToStrip, boolean matchCase)
    Removes all occurances of a string from the end of another string.
    static String
    stripFromFront(String source, String stringToStrip)
    Removes all occurances of a string from the front of another string in a case-sensitive manner.
    static String
    stripFromFront(String source, String stringToStrip, boolean matchCase)
    Removes all occurances of a string from the front of another string.
    static List<String>
    toArrayList(String[] stringArray)
    Creates a new ArrayList, containing the elements of a supplied array of String objects.
    static String
    toString(byte[] bytes, String encoding)
    Creates a String for the provided byte array and encoding
    static String[]
    Creates a new array of String objects, containing the elements of a supplied Iterator.
    static String
    trim(String source)
    Ensures that all whitespace is removed from a String.
    static String
    Ensure that the first character of the provided string is lower case.
    static String
    wordWrap(String input, int width, Locale locale)
    Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner.

    Methods inherited from class java.lang.Object

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

    • ENCODING_US_ASCII

      public static String ENCODING_US_ASCII
    • ENCODING_ISO_8859_1

      public static String ENCODING_ISO_8859_1
    • ENCODING_ISO_8859_2

      public static String ENCODING_ISO_8859_2
    • ENCODING_ISO_8859_5

      public static String ENCODING_ISO_8859_5
    • ENCODING_UTF_8

      public static String ENCODING_UTF_8
    • ENCODING_UTF_16BE

      public static String ENCODING_UTF_16BE
    • ENCODING_UTF_16LE

      public static String ENCODING_UTF_16LE
    • ENCODING_UTF_16

      public static String ENCODING_UTF_16
    • CHARSET_US_ASCII

      public static Charset CHARSET_US_ASCII
    • HEX_DIGITS

      public static final char[] HEX_DIGITS
    • HEX_DIGITS_LOWER

      public static final char[] HEX_DIGITS_LOWER
    • BBCODE_COLOR

      public static final Pattern BBCODE_COLOR
    • BBCODE_SIZE

      public static final Pattern BBCODE_SIZE
    • BBCODE_URL_SHORT

      public static final Pattern BBCODE_URL_SHORT
    • BBCODE_URL_LONG

      public static final Pattern BBCODE_URL_LONG
    • BBCODE_IMG

      public static final Pattern BBCODE_IMG
    • BBCODE_QUOTE_LONG

      public static final Pattern BBCODE_QUOTE_LONG
    • BBCODE_BAREURL

      public static final Pattern BBCODE_BAREURL
  • Method Details

    • encodeClassname

      public static String encodeClassname(String name)
      Transforms a provided String object into a new string, containing only valid characters for a java class name.
      Parameters:
      name - The string that has to be transformed into a valid class name.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeUrl

      public static String encodeUrl(String source)
      Transforms a provided String object into a new string, containing only valid URL characters in the UTF-8 encoding.
      Parameters:
      source - The string that has to be transformed into a valid URL string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeUrl

      public static String encodeUrl(String source, char... allow)
      Transforms a provided String object into a new string, containing only valid URL characters in the UTF-8 encoding.
      Parameters:
      source - The string that has to be transformed into a valid URL string.
      allow - Additional characters to allow.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeUrl

      public static String encodeUrl(String source, String allow)
      Transforms a provided String object into a new string, containing only valid URL characters in the UTF-8 encoding.
      Parameters:
      source - The string that has to be transformed into a valid URL string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • appendHexDigit

      public static void appendHexDigit(StringBuilder out, int number)
      Appends the hexadecimal digit of the provided number.
      Parameters:
      out - the string builder to append to
      number - the number who's first digit will be appended in hexadecimal
      Since:
      1.0
    • appendHexDigitLower

      public static void appendHexDigitLower(StringBuilder out, int number)
      Appends the lowercase hexadecimal digit of the provided number.
      Parameters:
      out - the string builder to append to
      number - the number who's first digit will be appended in hexadecimal
      Since:
      1.5.7
    • decodeUrl

      public static String decodeUrl(String source)
      Transforms a provided String URL into a new string, containing decoded URL characters in the UTF-8 encoding.
      Parameters:
      source - The string URL that has to be decoded
      Returns:
      The decoded String object.
      Since:
      1.0
      See Also:
    • decodeHtml

      public static String decodeHtml(String source)
      Since:
      1.0
    • encodeHtml

      public static String encodeHtml(String source)
      Transforms a provided String object into a new string, containing only valid Html characters.
      Parameters:
      source - The string that has to be transformed into a valid Html string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeHtmlDefensive

      public static String encodeHtmlDefensive(String source)
      Transforms a provided String object into a new string, containing as much as possible Html characters. It is safe to already feed existing Html to this method since &, < and > will not be encoded.
      Parameters:
      source - The string that has to be transformed into a valid Html string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeXml

      public static String encodeXml(String source)
      Transforms a provided String object into a new string, containing only valid XML characters.
      Parameters:
      source - The string that has to be transformed into a valid XML string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeString

      public static String encodeString(String source)
      Transforms a provided String object into a new string, containing only valid String characters.
      Parameters:
      source - The string that has to be transformed into a valid sequence of String characters.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeUnicode

      public static String encodeUnicode(String source)
      Transforms a provided String object into a series of unicode escape codes.
      Parameters:
      source - The string that has to be transformed into a valid sequence of unicode escape codes
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeSql

      public static String encodeSql(String source)
      Transforms a provided String object into a new string, containing only valid Sql characters.
      Parameters:
      source - The string that has to be transformed into a valid Sql string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeLatex

      public static String encodeLatex(String source)
      Transforms a provided String object into a new string, containing only valid LaTeX characters.
      Parameters:
      source - The string that has to be transformed into a valid LaTeX string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeJson

      public static String encodeJson(String source)
      Transforms a provided String object into a new string, containing only valid Json characters.
      Parameters:
      source - The string that has to be transformed into a valid LaTeX string.
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeRegexp

      public static String encodeRegexp(String source)
      Transforms a provided String object into a literal that can be included into a regular expression Pattern as-is. None of the regular expression escapes in the string will be functional anymore.
      Parameters:
      source - The string that has to be escaped as a literal
      Returns:
      The encoded String object.
      Since:
      1.0
      See Also:
    • encodeHex

      public static String encodeHex(byte[] bytes)
      Generates an uppercase hexadecimal string for the provided byte array.
      Parameters:
      bytes - the byte array to convert to a hex string
      Returns:
      the converted hexadecimal string
      Since:
      1.0
    • encodeHexLower

      public static String encodeHexLower(byte[] bytes)
      Generates a lowercase hexadecimal string for the provided byte array.
      Parameters:
      bytes - the byte array to convert to a hex string
      Returns:
      the converted hexadecimal string
      Since:
      1.5.7
    • encodeBase64

      public static String encodeBase64(byte[] bytes)
      Encodes byte array to Base64 String.
      Parameters:
      bytes - Bytes to encode.
      Returns:
      Encoded byte array bytes as a String.
      Since:
      1.1
    • encodeBase32

      public static String encodeBase32(byte[] bytes)
      Encodes byte array to Base32 String.
      Parameters:
      bytes - Bytes to encode.
      Returns:
      Encoded byte array bytes as a String.
      Since:
      1.0
    • count

      public static int count(String source, String substring)
      Counts the number of times a substring occures in a provided string in a case-sensitive manner.
      Parameters:
      source - The String object that will be searched in.
      substring - The string whose occurances will we counted.
      Returns:
      An int value containing the number of occurances of the substring.
      Since:
      1.0
    • count

      public static int count(String source, String substring, boolean matchCase)
      Counts the number of times a substring occures in a provided string.
      Parameters:
      source - The String object that will be searched in.
      substring - The string whose occurances will we counted.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      An int value containing the number of occurances of the substring.
      Since:
      1.0
    • split

      public static List<String> split(String source, String separator)
      Splits a string into different parts, using a separator string to detect the seperation boundaries in a case-sensitive manner. The separator will not be included in the list of parts.
      Parameters:
      source - The string that will be split into parts.
      separator - The separator string that will be used to determine the parts.
      Returns:
      An ArrayList containing the parts as String objects.
      Since:
      1.0
    • split

      public static List<String> split(String source, String separator, boolean matchCase)
      Splits a string into different parts, using a separator string to detect the seperation boundaries. The separator will not be included in the list of parts.
      Parameters:
      source - The string that will be split into parts.
      separator - The separator string that will be used to determine the parts.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      An ArrayList containing the parts as String objects.
      Since:
      1.0
    • splitToArray

      public static String[] splitToArray(String source, String separator)
      Splits a string into different parts, using a separator string to detect the seperation boundaries in a case-sensitive manner. The separator will not be included in the parts array.
      Parameters:
      source - The string that will be split into parts.
      separator - The separator string that will be used to determine the parts.
      Returns:
      A String[] array containing the seperated parts.
      Since:
      1.0
    • splitToArray

      public static String[] splitToArray(String source, String separator, boolean matchCase)
      Splits a string into different parts, using a separator string to detect the seperation boundaries. The separator will not be included in the parts array.
      Parameters:
      source - The string that will be split into parts.
      separator - The separator string that will be used to determine the parts.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      A String[] array containing the seperated parts.
      Since:
      1.0
    • splitToIntArray

      public static int[] splitToIntArray(String source, String separator)
      Splits a string into integers, using a separator string to detect the seperation boundaries in a case-sensitive manner. If a part couldn't be converted to an integer, it will be omitted from the resulting array.
      Parameters:
      source - The string that will be split into integers.
      separator - The separator string that will be used to determine the parts.
      Returns:
      An int[] array containing the seperated parts.
      Since:
      1.0
    • splitToIntArray

      public static int[] splitToIntArray(String source, String separator, boolean matchCase)
      Splits a string into integers, using a separator string to detect the seperation boundaries. If a part couldn't be converted to an integer, it will be omitted from the resulting array.
      Parameters:
      source - The string that will be split into integers.
      separator - The separator string that will be used to determine the parts.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      An int[] array containing the seperated parts.
      Since:
      1.0
    • splitToByteArray

      public static byte[] splitToByteArray(String source, String separator)
      Splits a string into bytes, using a separator string to detect the seperation boundaries in a case-sensitive manner. If a part couldn't be converted to a byte, it will be omitted from the resulting array.
      Parameters:
      source - The string that will be split into bytes.
      separator - The separator string that will be used to determine the parts.
      Returns:
      A byte[] array containing the bytes.
      Since:
      1.0
    • splitToByteArray

      public static byte[] splitToByteArray(String source, String separator, boolean matchCase)
      Splits a string into bytes, using a separator string to detect the seperation boundaries. If a part couldn't be converted to a byte, it will be omitted from the resulting array.
      Parameters:
      source - The string that will be split into bytes.
      separator - The separator string that will be used to determine the parts.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      A byte[] array containing the bytes.
      Since:
      1.0
    • stripFromFront

      public static String stripFromFront(String source, String stringToStrip)
      Removes all occurances of a string from the front of another string in a case-sensitive manner.
      Parameters:
      source - The string in which the matching will be done.
      stringToStrip - The string that will be stripped from the front.
      Returns:
      A new String containing the stripped result.
      Since:
      1.0
    • stripFromFront

      public static String stripFromFront(String source, String stringToStrip, boolean matchCase)
      Removes all occurances of a string from the front of another string.
      Parameters:
      source - The string in which the matching will be done.
      stringToStrip - The string that will be stripped from the front.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      A new String containing the stripping result.
      Since:
      1.0
    • stripFromEnd

      public static String stripFromEnd(String source, String stringToStrip)
      Removes all occurances of a string from the end of another string in a case-sensitive manner.
      Parameters:
      source - The string in which the matching will be done.
      stringToStrip - The string that will be stripped from the end.
      Returns:
      A new String containing the stripped result.
      Since:
      1.0
    • stripFromEnd

      public static String stripFromEnd(String source, String stringToStrip, boolean matchCase)
      Removes all occurances of a string from the end of another string.
      Parameters:
      source - The string in which the matching will be done.
      stringToStrip - The string that will be stripped from the end.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      A new String containing the stripped result.
      Since:
      1.0
    • replace

      public static String replace(String source, String stringToReplace, String replacementString)
      Searches for a string within a specified string in a case-sensitive manner and replaces every match with another string.
      Parameters:
      source - The string in which the matching parts will be replaced.
      stringToReplace - The string that will be searched for.
      replacementString - The string that will replace each matching part.
      Returns:
      A new String object containing the replacement result.
      Since:
      1.0
    • replace

      public static String replace(String source, String stringToReplace, String replacementString, boolean matchCase)
      Searches for a string within a specified string and replaces every match with another string.
      Parameters:
      source - The string in which the matching parts will be replaced.
      stringToReplace - The string that will be searched for.
      replacementString - The string that will replace each matching part.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      A new String object containing the replacement result.
      Since:
      1.0
    • repeat

      public static String repeat(String source, int count)
      Creates a new string that contains the provided string a number of times.
      Parameters:
      source - The string that will be repeated.
      count - The number of times that the string will be repeated.
      Returns:
      A new String object containing the repeated concatenation result.
      Since:
      1.0
    • toString

      public static String toString(byte[] bytes, String encoding)
      Creates a String for the provided byte array and encoding
      Parameters:
      bytes - The byte array to convert.
      encoding - The encoding to use for the string conversion.
      Returns:
      The converted String.
      Since:
      1.0
    • toStringArray

      public static String[] toStringArray(Iterator<String> iterator)
      Creates a new array of String objects, containing the elements of a supplied Iterator.
      Parameters:
      iterator - The iterator containing the elements to create the array with.
      Returns:
      The new String array.
      Since:
      1.0
    • toArrayList

      public static List<String> toArrayList(String[] stringArray)
      Creates a new ArrayList, containing the elements of a supplied array of String objects.
      Parameters:
      stringArray - The array of String objects that have to be converted.
      Returns:
      The new ArrayList with the elements of the String array.
      Since:
      1.0
    • join

      public static String join(Collection<?> collection, String separator)
      Creates a new String object, containing the elements of a supplied Collection of String objects joined by a given separator.
      Parameters:
      collection - The Collection containing the elements to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(Object[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The object array containing the elements to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(Object[] array, String separator, String delimiter)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The object array containing the elements to join.
      separator - The separator used to join the string elements.
      delimiter - The delimiter used to surround the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(Object[] array, String separator, String delimiter, boolean encodeStrings)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The object array containing the elements to join.
      separator - The separator used to join the string elements.
      delimiter - The delimiter used to surround the string elements.
      encodeStrings - Indicates whether the characters of the string representation of the Array values should be encoded.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(boolean[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The boolean array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(byte[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The byte array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(double[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The double array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(float[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The float array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(int[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The integer array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(long[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The long array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(short[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The short array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(char[] array, String separator)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The char array containing the values to join.
      separator - The separator used to join the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • join

      public static String join(char[] array, String separator, String delimiter)
      Creates a new String object, containing the elements of a supplied array, joined by a given separator.
      Parameters:
      array - The char array containing the values to join.
      separator - The separator used to join the string elements.
      delimiter - The delimiter used to surround the string elements.
      Returns:
      A new String with the join result.
      Since:
      1.0
    • indicesOf

      public static int[] indicesOf(String source, String substring)
      Returns an array that contains all the occurances of a substring in a string in the correct order. The search will be performed in a case-sensitive manner.
      Parameters:
      source - The String object that will be searched in.
      substring - The string whose occurances will we counted.
      Returns:
      An int[] array containing the indices of the substring.
      Since:
      1.0
    • indicesOf

      public static int[] indicesOf(String source, String substring, boolean matchCase)
      Returns an array that contains all the occurances of a substring in a string in the correct order.
      Parameters:
      source - The String object that will be searched in.
      substring - The string whose occurances will we counted.
      matchCase - A boolean indicating if the match is going to be performed in a case-sensitive manner or not.
      Returns:
      An int[] array containing the indices of the substring.
      Since:
      1.0
    • getMatchingRegexp

      public static Matcher getMatchingRegexp(String value, Collection<Pattern> regexps)
      Matches a collection of regular expressions against a string.
      Parameters:
      value - The String that will be checked.
      regexps - The collection of regular expressions against which the match will be performed.
      Returns:
      The Matcher instance that corresponds to the String that returned a successful match; or

      null if no match could be found.

      Since:
      1.0
    • getRegexpMatch

      public static Matcher getRegexpMatch(Collection<String> values, Pattern regexp)
      Matches a collection of strings against a regular expression.
      Parameters:
      values - The Collection of String objects that will be checked.
      regexp - The regular expression Pattern against which the matches will be performed.
      Returns:
      The Matcher instance that corresponds to the String that returned a successful match; or

      null if no match could be found.

      Since:
      1.0
    • filter

      public static boolean filter(String name, Pattern included, Pattern excluded)
      Checks if the name filters through an including and an excluding regular expression.
      Parameters:
      name - The String that will be filtered.
      included - The regular expressions that needs to succeed
      excluded - The regular expressions that needs to fail
      Returns:
      true if the name filtered through correctly; or

      false otherwise.

      Since:
      1.0
    • filter

      public static boolean filter(String name, Pattern included, Pattern excluded, boolean matches)
      Checks if the name filters through an including and an excluding regular expression.
      Parameters:
      name - The String that will be filtered.
      included - The regular expressions that needs to succeed
      excluded - The regular expressions that needs to fail
      matches - Indicates whether it should be a full match or a contains
      Returns:
      true if the name filtered through correctly; or

      false otherwise.

      Since:
      1.5.18
    • filter

      public static boolean filter(String name, List<Pattern> included, List<Pattern> excluded)
      Checks if the name filters through a series of including and excluding regular expressions.
      Parameters:
      name - The String that will be filtered.
      included - A list of regular expressions that need to succeed
      excluded - A list of regular expressions that need to fail
      Returns:
      true if the name filtered through correctly; or

      false otherwise.

      Since:
      1.5
    • filter

      public static boolean filter(String name, List<Pattern> included, List<Pattern> excluded, boolean matches)
      Checks if the name filters through a series of including and excluding regular expressions.
      Parameters:
      name - The String that will be filtered.
      included - A list of regular expressions that need to succeed
      excluded - A list of regular expressions that need to fail
      matches - Indicates whether it should be a full match or a contains
      Returns:
      true if the name filtered through correctly; or

      false otherwise.

      Since:
      1.5.18
    • filter

      public static boolean filter(String name, Pattern[] included, Pattern[] excluded)
      Checks if the name filters through a series of including and excluding regular expressions.
      Parameters:
      name - The String that will be filtered.
      included - An array of regular expressions that need to succeed
      excluded - An array of regular expressions that need to fail
      Returns:
      true if the name filtered through correctly; or

      false otherwise.

      Since:
      1.0
    • filter

      public static boolean filter(String name, Pattern[] included, Pattern[] excluded, boolean matches)
      Checks if the name filters through a series of including and excluding regular expressions.
      Parameters:
      name - The String that will be filtered.
      included - An array of regular expressions that need to succeed
      excluded - An array of regular expressions that need to fail
      matches - Indicates whether it should be a full match or a contains
      Returns:
      true if the name filtered through correctly; or

      false otherwise.

      Since:
      1.5.18
    • capitalize

      public static String capitalize(String source)
      Ensure that the first character of the provided string is upper case.
      Parameters:
      source - The String to capitalize.
      Returns:
      The capitalized String.
      Since:
      1.0
    • uncapitalize

      public static String uncapitalize(String source)
      Ensure that the first character of the provided string is lower case.
      Parameters:
      source - The String to uncapitalize.
      Returns:
      The uncapitalized String.
      Since:
      1.0
    • convertBbcode

      public static String convertBbcode(String source)
      Converts a BBCode marked-up text to regular html.
      Parameters:
      source - The text with BBCode tags.
      Returns:
      A String with the corresponding HTML code
      Since:
      1.0
    • convertBbcode

      public static String convertBbcode(String source, rife.tools.StringUtils.BbcodeOption... options)
      Converts a BBCode marked-up text to regular html.
      Parameters:
      source - The text with BBCode tags.
      Returns:
      A String with the corresponding HTML code
      Since:
      1.0
    • convertToBoolean

      public static boolean convertToBoolean(String value)
      Converts a String to a boolean value.
      Parameters:
      value - The String to convert.
      Returns:
      The corresponding boolean value.
      Since:
      1.0
    • convertTabsToSpaces

      public static String convertTabsToSpaces(String line, int tabWidth)
      Converts all tabs on a line to spaces according to the provided tab width.
      Parameters:
      line - The line whose tabs have to be converted.
      tabWidth - The tab width.
      Returns:
      A new String object containing the line with the replaced tabs.
      Since:
      1.0
    • trim

      public static String trim(String source)
      Ensures that all whitespace is removed from a String.

      It also works with a null argument.

      Parameters:
      source - The String to trim.
      Returns:
      The trimmed String.
      Since:
      1.0
    • getDocumentPosition

      public static DocumentPosition getDocumentPosition(String document, int characterIndex)
      Calculates the DocumentPosition of a character index in a document.
      Parameters:
      document - a String with the document where the position should be looked up in
      characterIndex - the index of the character
      Returns:
      the resulting DocumentPosition instance; or

      null if the characterIndex was invalid or if the document was null

      Since:
      1.0
    • wordWrap

      public static String wordWrap(String input, int width, Locale locale)
      Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner. If the width specified is less than 5 or greater than the input Strings length the string will be returned as is.

      Please note that this method can be lossy - trailing spaces on wrapped lines may be trimmed.

      Parameters:
      input - the String to reformat.
      width - the maximum length of any one line.
      Returns:
      a new String with reformatted as needed.
    • stripBlankLines

      public static String stripBlankLines(String text)
      Removes all blank lines from text.
      Parameters:
      text - the text to strip blank lines from
      Returns:
      the text without any blank lines
      Since:
      1.5.7
    • convertLineSeparator

      public static String convertLineSeparator(String text)
      Replaces \n with the system line separator.
      Parameters:
      text - the string in which the line separator should be replaced
      Returns:
      the new string with the replaced line separator
      Since:
      1.7.2