Class KmgStringTokenizer

    • Constructor Detail

      • KmgStringTokenizer

        public KmgStringTokenizer​(String text,
                                  String delim1,
                                  String delim2)
        Variant of StringTokenizer which supports two different types of delimiters, see Parameters delim1 and delim2.
        Examples:
            KmgStringTokenizer( "abc\t\txyz", "", "\t" ) returns "abc", "xyz"  // same result as StringTokenizer
            KmgStringTokenizer( "abc\t\txyz", "\t", "" ) returns "abc", "", "xyz"
            KmgStringTokenizer( "  abc \t  \t  xyz  ", "\t", " " ) returns "abc", "", "xyz"
            KmgStringTokenizer( " \t abc : xyz || ", "|\t", ": " ) returns "", "abc", "xyz", "", ""
         
        KmgStringTokenizer( text, "", delim2 ) is equivalent to java.util.StringTokenizer( text, delim2 )
        Parameters:
        text - string containing tokens separated by delimiters
        delim1 - consecutive delimiters of this type count separately and nextToken() returns "" (empty string)
        delim2 - delimiters of this type adjacent to another delimiter are ignored ⇒ consecutive delimiters count as one single delimiter
      • KmgStringTokenizer

        public KmgStringTokenizer​(String text)
        Shortcut of KmgStringTokenizer( text, "\t\n\r\f", " " ) .
    • Method Detail

      • reset

        public KmgStringTokenizer reset()
        Resets the internal parse position (The delimiter set remains the same).
        Returns:
        this
      • setDelimiters

        public KmgStringTokenizer setDelimiters​(String delim1,
                                                String delim2)
        Sets the delimiters to the given values (The parse position remains the same, "" ignores the delimiter, null does not change the delimiter).
        Returns:
        this
      • hasMoreElements

        public boolean hasMoreElements()
        Returns true, if a subsequent call of nextElement() will return a result which is not null.
        Specified by:
        hasMoreElements in interface Enumeration
      • next

        public Object next()
        Returns the next token or null, if no more tokens available.
        Specified by:
        next in interface Iterator
      • nextElement

        public Object nextElement()
        Returns the next token or null, if no more tokens available.
        Specified by:
        nextElement in interface Enumeration
      • nextToken

        public String nextToken()
        Returns the next token or null, if no more tokens available.
      • nextToken

        public String nextToken​(String delim1,
                                String delim2)
        Returns the next token after changing the delimiters to the given values. The new delimiter set remains the default after this call.
      • get

        public String get​(int i)
        Returns the next token after skipping i tokens.
      • split

        public String[] split​(int n)
        Returns an array containing n (remaining) tokens. If text does not contain sufficient tokens, the missing array elements are null.
      • getRemaining

        public String getRemaining()
        Returns all remaining text without considering any delimiters.
      • test

        public static String[] test​(Enumeration st)
        Returns an array containing the String representation of the elements of st.
      • main

        public static void main​(String[] args)
        Test.