Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-23
4
Medium Priority
?
339 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 1200 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 400 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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

886 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