Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String tokenizers as HEX characters, how to do............

Status
Not open for further replies.

abc73

Programmer
Apr 28, 2004
89
US
I am trying to tokenize a string that contains non-displayable characters i.e. EBCDIC or ASCII. How to split a string based on some EBCDIC or ASCII characters. e.g.

X'1D', X'1C', X'1A' and X'c8' represents the non-displayable characters in the string that I need to set as tokenizers, the tokenizers are placed in the string just to visualize what I want to do:

"I am trying to split this string X'1D'and also testing X'1C' along with X'1A' and this too X'c8', and see if works."

and after parsing or splitting my final result will be like as:

I am trying to split this string
and also testing
along with
and this too
, and see if works.


As the original string will look like as follows where  represents any HEX character as described in the above sample which I need to set as a Token.  can be any HEX character but I just want to split on some of them.

"StartTEST1TEST2TEST3TEST4TEST5TEST6TEST7TEST812END"

based on my Tokens the output may look as below:
StartTEST1
TEST2
TEST3TEST4TEST5TEST6
TEST7
TEST8
1
2
END


Any idea how to do this. Any help is appreciated.

Thanks
 
A StringTokenizer constructor may take as one of its arguments a String specifying the delimiter character(s). A String constructor may take as one of its aruguments a byte[] array. Why not build a byte array with your HEX characters and make that into the delimiter string?

Bob Rashkin
rrashkin@csc.com
 
How can I print the HEX values of the non-displayable characters. e.g.

"StartTEST1TEST2TEST3TEST4TEST5TEST6TEST7TEST812END"

How can I print the HEX values of


in the above string. Any help is appreciated.

Thanks
 
I don't think you can print them as characters (they are, after all, unprintable). You can treat the Hex as an integer and get the int that the hex string represents: parseInt(String s, int radix). Then you can get a hexString back: toHexString(int i).

Bob Rashkin
rrashkin@csc.com
 
 represents any HEX character as described in the above sample which I need to set as a Token.  can be any HEX character but I just want to split on some of them.

"StartTEST1TEST2TEST3TEST4TEST5TEST6TEST7TEST812END"

based on my Tokens the output may look as below:
StartTEST1
TEST2
TEST3TEST4TEST5TEST6
TEST7
TEST8
1
2
END


Any idea how to do this. Any help is appreciated.
Using byte array to tokenize is not working. Any idea what I am doing wrong
 
Sorry here is the final version of my Question:

I am trying to tokenize a string that contains non-displayable characters i.e. EBCDIC or ASCII. How to split a string based on some EBCDIC or ASCII characters. e.g.

Her  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
 
I think Bong answered you, you can use a StringTokenizer passing as tokens the bytes representing the EBCID character you want to split.

Cheers.

Dian
 
I tried to pass the byte but it didn't work may be I am doing it wrong. I even tried the following but wrong result. e.g. as in the above eaxample  is \29 but when using string tokenizer

StringTokenizer st = new StringTokenizer(string, "\29");

doesn't work. Probably I am doing something wrong. How can set HEX character as token in StringTokenizer. Thanks
 
Should be something like this:

Code:
byte[] delimiters = new byte[...];
demiliters[0] = 29;

...

StringTokenizer st = new StringTokenizer(string, new String(delimiters));

Cheers.

Dian
 
Thanks for all the help I got it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top