Solved

Best way to parse a string with multiple repeating items

Posted on 2007-03-22
7
227 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
network + 7 80
firstswap challenge 20 65
AWS and Java and Rest - newbie question (Is this an authentication issue) 4 65
Cipher Configuration on Apache HTTPD 4 50
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

932 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

12 Experts available now in Live!

Get 1:1 Help Now