Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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, f…

912 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

19 Experts available now in Live!

Get 1:1 Help Now