Solved

Best way to parse a string with multiple repeating items

Posted on 2007-03-22
7
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
throw exception 21 81
Java string replace 11 80
Chrome and Firefox Java 5 90
hashmap order 17 63
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

710 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