Solved

Best way to parse a string with multiple repeating items

Posted on 2007-03-22
7
216 Views
Last Modified: 2010-03-31
Hi

I am trying to parse repeating data that is in a byte array and wondering what would be the most efficient way to go about it.

example data in byte array
010107 Name jacksand Address 1000mainstreet City Madison State Wisconsin ZIP 12211,010107 Name rickLogan Address 1000mainstreet City SanDiego State California ZIP 12211

I was thinking of changing the byte array to a string
Using split to separate the two records
then indexOf to find where Name, Address, City, State, and Zip positions are in each of the string
then use substring to grab each

I think this may not be the best way to go about this?

Would you recommend keeping it in the byte array and using a StringBuffer?

Thanks
ryno71
0
Comment
Question by:ryno71
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18775670
Yes, i'd create a String and call split on it
0
 

Author Comment

by:ryno71
ID: 18775701
That gets me to split the two different records but if I wanted the following data Name, Address, City,etc (with the actual words) would I use indexOf and substring to grab them? After I have said data I could always use split again to separate where/if there are blanks
0
 
LVL 92

Expert Comment

by:objects
ID: 18775849
use spit() twice, one to break records, and then on each record to split fields
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 18775854
>>After I have said data I could always use split again

Yes, that's right
0
 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 18775861
String[] records = line.split(",");
for (int i=0; i<records.length; i++)
{
   String[] fields = records[i].spit(" "); // or whatever the actual delimiter is
   String name = fileds[2];
   etc.
0
 

Author Comment

by:ryno71
ID: 18809924
thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18814484
:-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now