Solved

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

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

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

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