Solved

Best way to parse a string with multiple repeating items

Posted on 2007-03-22
7
251 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
servlet example 17 59
Is there a simpler dropbox system? 10 44
project copy paste issue 1 61
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

740 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