4 Replies Latest reply: Apr 4, 2007 10:00 AM by 800649 RSS

    StringTokenizer

    807599
      Hello everybody.

      I am trying to develop a software that will be able to identify some characters in a row. I thought that the StringTokenizer is doing such thing but and I used the characters that I wanted as delimiter. But I have realized that the delimiter of the StringTokenizer gets each one by one the characters of the delimiter and not as a whole word.

      Do anyone of you know how can I do the same thing that the StringTokenizer does but using a whole word as a delimiter?

      Thanks for your help.
        • 1. Re: StringTokenizer
          807599
          If I understand your problem correctly
          in the java API the constructor
          public StringTokenizer(String str,
                                 String delim,
                                 boolean returnDelims)
          does exactly what you want .. your delimiter can also be an String..

          Hope this helps
          • 2. Re: StringTokenizer
            800649
            I am trying to develop a software that will be able to identify some characters in a row.
            use regexp instead :http://java.sun.com/docs/books/tutorial/essential/regex/
            But I have realized that the delimiter of the StringTokenizer gets each one by one the characters of the delimiter and not as a whole word.
            I don't think so. http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html#StringTokenizer(java.lang.String)
            • 3. Re: StringTokenizer
              807599
              If I understand your problem correctly
              in the java API the constructor
                public StringTokenizer(String str,
                                       String delim,
                boolean returnDelims) 
              does exactly what you want .. your delimiter can also
              be an String..
              No, that's even worse: it will return each delimiter character, separately, along with the tokens. @OP, What you want is String's split() method.
              • 4. Re: StringTokenizer
                807599
                yes.... use the split() method in String class.... construct ur regex to split ur string based on a word.. refer to the String JavaDoc for more info