Solved

Best way to parse a string with multiple repeating items

Posted on 2007-03-22
7
260 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

630 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