Package io.ebean.util

Class StringHelper


  • public class StringHelper
    extends Object
    Utility String class that supports String manipulation functions.
    • Method Detail

      • countOccurances

        public static int countOccurances​(String content,
                                          String occurs)
        Returns the number of times a particular String occurs in another String. e.g. count the number of single quotes.
      • delimitedToMap

        public static Map<String,​StringdelimitedToMap​(String allNameValuePairs,
                                                              String listDelimiter,
                                                              String nameValueSeparator)
        Parses out a list of Name Value pairs that are delimited together. Will always return a StringMap. If allNameValuePairs is null, or no name values can be parsed out an empty StringMap is returned.
        Parameters:
        allNameValuePairs - the entire string to be parsed.
        listDelimiter - (typically ';') the delimited between the list
        nameValueSeparator - (typically '=') the separator between the name and value
      • trimFront

        public static String trimFront​(String source,
                                       String trim)
        Trims off recurring strings from the front of a string.
        Parameters:
        source - the source string
        trim - the string to trim off the front
      • isNull

        public static boolean isNull​(String value)
        Return true if the value is null or an empty string.
      • delimitedToArray

        public static String[] delimitedToArray​(String str,
                                                String delimiter,
                                                boolean keepEmpties)
        Convert a string that has delimited values (say comma delimited) in a String[]. You must explicitly choose whether or not to include empty values (say two commas that a right beside each other.

        e.g. "alpha,beta,,theta"
        With keepEmpties true, this results in a String[] of size 4 with the third one having a String of 0 length. With keepEmpties false, this results in a String[] of size 3.

        e.g. ",alpha,beta,,theta,"
        With keepEmpties true, this results in a String[] of size 6 with the 1st,4th and 6th one having a String of 0 length. With keepEmpties false, this results in a String[] of size 3.

      • replaceString

        public static String replaceString​(String source,
                                           String match,
                                           String replace)
        This method takes a String and will replace all occurrences of the match String with that of the replace String.
        Parameters:
        source - the source string
        match - the string used to find a match
        replace - the string used to replace match with
        Returns:
        the source string after the search and replace
      • replaceString

        public static String replaceString​(String source,
                                           String match,
                                           String replace,
                                           int additionalSize,
                                           int startPos,
                                           int endPos)
        Additionally specify the additionalSize to add to the buffer. This will make the buffer bigger so that it doesn't have to grow when replacement occurs.
      • replaceStringMulti

        public static String replaceStringMulti​(String source,
                                                String[] match,
                                                String replace)
        A search and replace with multiple matching strings.

        Useful when converting CRNL CR and NL all to a BR tag for example.

        
        
         String[] multi = { "\r\n", "\r", "\n" };
         content = StringHelper.replaceStringMulti(content, multi, "<br/>");
        
         
      • replaceStringMulti

        public static String replaceStringMulti​(String source,
                                                String[] match,
                                                String replace,
                                                int additionalSize,
                                                int startPos,
                                                int endPos)
        Additionally specify an additional size estimate for the buffer plus start and end positions.

        The start and end positions can limit the search and replace. Otherwise these default to startPos = 0 and endPos = source.length().

      • splitNames

        public static String[] splitNames​(String names)
        Splits at any whitespace "," or ";" and trims the result. It does not return empty entries.