Solved

How to break records from a single line of multiple records? VB.Net or C#

Posted on 2012-03-23
4
329 Views
Last Modified: 2012-06-27
I have a file with multiple records entered on a single line without a record breaker as follows.

AAABUS6666666   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Smith       John       540 N.VIA VALVERDEAAABUS7777777   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Carillo       Dave       201 Verdugo AveAAABUS8888888   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Stevenson       Craig       540 N.VIA VALVERDE




I would like to break these records with a ; or any special character
Please advise how can this be accomplished in VB.Net.

The only thing that is unique and can indicate a record breaker is "01  AAAB,INC."  

Each record is not fixed length.
AAABUS is repeated twice on each line.

After processing, the final output should look like(Please note the ; and line break):
AAABUS6666666   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Smith       John       540 N.VIA VALVERDE;
AAABUS7777777   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Carillo       Dave       201 Verdugo Ave;
AAABUS8888888   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Stevenson       Craig       600 N.Hollywood;

Thanks.
0
Comment
Question by:Ricky66
4 Comments
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 300 total points
ID: 37759861
You could do something like this to break it up but your record breaker indicator is not as simple as the "01 AAAB,INC.".  That seems to be somewhere in the middle of the record.

 Dim sSeparator As String = "01  AAAB,INC."

        Dim sString As String = "AAABUS6666666   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Smith       John       540 N.VIA VALVERDEAAABUS7777777   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Carillo       Dave       201 Verdugo AveAAABUS8888888   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Stevenson       Craig       540 N.VIA VALVERDE"
        Dim sb As New System.Text.StringBuilder
        For Each s As String In sString.Split(sSeparator)
            sb.Append(s)
        Next

The key is identifying the break.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
ID: 37765042
It appears from your sample breakup that each record starts with AAABUS. Is that right?

If it is then you can do a simple

Dim newstr as string = oldstr.Replace("AAABUS", ";" & vbcrlf & "AAABUS")
0
 
LVL 12

Assisted Solution

by:Anuradha Goli
Anuradha Goli earned 100 total points
ID: 37806865
I am posting the sample code in c#.hope you can implement same logic in VB.net
 
protected void Button1_Click(object sender, EventArgs e)
    {
        string k1 = "";
        string str = "AAABUS6666666   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Smith       John       540 N.VIA VALVERDEAAABUS7777777   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Carillo       Dave       201 Verdugo AveAAABUS8888888   01  AAAB,INC.                1105070522AAABUS9147930   21  0008060362Stevenson       Craig       540 N.VIA VALVERDE";
         int[] j = new int[500];
        for (int i = 0, k=0; i < str.Length; i++,k++)
        {
            j[k] = str.LastIndexOf("AAABUS");

            k1 += str.Substring(j[k], (str.Length - j[k]));
            if (k % 2 == 1)
            {
                k1 += "<br />" ;
            }
                str = str.Substring(0, j[k]);    
        }
        Response.Write(k1);
    }

Open in new window


Hope this helps you better
output.png
0
 

Author Closing Comment

by:Ricky66
ID: 37820196
Thanks!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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

11 Experts available now in Live!

Get 1:1 Help Now