FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   how to split this string? StringTokenizer,split()
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: how to split this string? StringTokenizer,split()  (Read 475 times)
JTsang

Email
how to split this string? StringTokenizer,split()
« on: Nov 30th, 2004, 5:30pm »

Hi there,
 
I am trying to write a simple JAVA function using a very specific split requirement.
Here's the explanation of what I'm trying to do.
 
I have one string which contains many records:
 
HDRRXCTDRRZYDJSKF0DCKDI9999292929200039293029DFTHD3434339342903940349039 3094093DFTB53444532432432DFTB00054544545455DFTTDFRH3444343423
 
It currently has no delimeters which mark the end of a record. This is exactly how I receive it. What I need to do it split this string according to certain tags that exist. (These tags mark the start and end of each record). These tags are (HDRR, DFTH, DFTB, DFTT, DFRH). This string will be of variable size which is why I need to split using the above specific tags. I require my output to look like this:
 
HDRRXCTDRRZYDJSKF0DCKDI9999292929200039293029
DFTHD34343393429039403490393094093
DFTB53444532432432
DFTB00054544545455
DFTT
DFRH3444343423
 
As you can see, I have inserted a CRLF wherever I come across a known tag (jst before the tag infact), so that the start of each line begins with this new tag/ record.
 
I have played around with the split function and the StringTokenizer with no success.
does anyone have any ideas on how to achieve this?
 
Many thanks in advance,
 
Jeff
« Last Edit: Nov 30th, 2004, 5:31pm by JTsang »  
TomC

WWW
Re: how to split this string? StringTokenizer,spli
« Reply #1 on: Nov 30th, 2004, 6:05pm »

Have a look at the String class in java (google for Java String, I imagine).  It has an indexOf function and a substring function, so you can find "HDRR", "DFTH", etc. and then get the substrings.  There isn't really a neater way to parse something with multiple delimiters.
 
Pages: 1 

« Previous topic | Next topic »