Solved

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

Posted on 2012-03-23
4
326 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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

20 Experts available now in Live!

Get 1:1 Help Now