Click to See Complete Forum and Search --> : Tokenizing a string with HEX characters


rockets12345
November 23rd, 2004, 09:36 PM
I am trying to tokenize a string that contains non-displayable characters i.e. HEX. How to split a string based on some HEX characters. e.g.

Here  represents any HEX character which I want to to set as part of Token along with some string as a Token.  can be any HEX character but I just want to split on some of them e.g. in the following sample string I want to split at TEST2

"StartTEST1TEST2TEST3TEST2TEST4TEST5TEST6TEST2TEST7TEST812END"
based on my Tokens the output should look as below:
StartTEST1
TEST3
TEST4TEST5TEST6
TEST7TEST812END
Any idea how to do this. Any help is appreciated.

Thanks

fbafelipe
November 24th, 2004, 04:44 PM
try it using the class StringTokenizer

dlorde
November 24th, 2004, 06:38 PM
The StringTokenizer class is deprecated. The canonical way of splitting strings is to use String.split(...) (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)) which uses a regular expression to break the string into an array of substrings.

The Pattern (http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sum) class documents how to develop a regular expression, and shows how hex values can be used.

The greatest obstacle to discovery is not ignorance, but the illusion of knowledge...
D. Boorstin