Re: String builder (Parsing vertically presented records)



IlCSP,

Why did you not go on with Cerebrus code. It is another approach, I only
wanted to tell that the SB was in my sample as well.

My sample was by the way full of typing and other errors. And because that
you are busy already so long here a better one if you don't succeed with
that of Cerebrus..
\\\
Dim strRdr As New IO.StreamReader("C:\test.txt")
Dim strWrt As New IO.StreamWriter("C:\TestO.txt")
Dim StrLine As String = strRdr.ReadLine()
StrLine = strRdr.ReadLine()
Dim sb As New System.Text.StringBuilder(StrLine.Substring(0, 9))
Do Until StrLine Is Nothing
Dim fields() As String = StrLine.Split(" "c)
If fields.Length = 2 Then
sb.Append(fields(1))
Else
sb.Append(fields(1) & "," & fields(2))
End If
StrLine = strRdr.ReadLine()
If Not StrLine Is Nothing Then
If StrLine.IndexOf("NewRegID") > -1 Then
strWrt.WriteLine(sb.ToString)
sb = New System.Text.StringBuilder(StrLine.Substring(0,
9))
StrLine = strRdr.ReadLine()
Else
sb.Append(",")
End If
End If
Loop
strWrt.WriteLine(sb.ToString)
strRdr.Close()
strWrt.Close()
///


The result withouth that crazy thirth line that you showed is.

2145551341,Y,2,N,3,Y,4,1,5,Y,6,Y,7,Y,8,Y,9,1,10,Y,11,Y,12,Y,13,Y,14,Y,15,1,16,17,Y,18,Y,19,Y,20,Y,21,1,22,N,23,N,24,1,25,2
2140164211,Y,2,Y,3,Y,4,1,5,Y,6,7,Y,8,Y,9,1,10,Y,11,N,12,Y,13,Y,14,Y,15,1,16,Y,17,18,Y,19,Y,20,Y,21,1,21,1,22,Y,23,N,24,2,25,3

I hope this helps,

Cor


.



Relevant Pages

  • Re: Build an array from a text file
    ... Dim strLine As String ... Dim strMaterial As String ... ' Test dictionary by checking on the value for material Steel ...
    (microsoft.public.word.vba.general)
  • Re: Fixed Address Function
    ... Public Function FixedAddressAs String ... 'vbCrLf Carriage return/line feed ... Dim newAddress As String ... Dim strLine As String ...
    (microsoft.public.access.queries)
  • Re: Fixed Address Function
    ... Public Function FixedAddressAs String ... 'vbCrLf Carriage return/line feed ... Dim newAddress As String ... Dim strLine As String ...
    (microsoft.public.access.queries)
  • Re: Text file I/O in VBA
    ... which the header or other lines will not have. ... Dim f1 As Integer ... Dim fOutput As String ... Input #1, strLIne ...
    (microsoft.public.access.modulesdaovba)
  • Re: Find/Replace in csv file - using VB
    ... Dim strLine As String ... Dim strLineBreak As String ... Dim strinputfilename As String ... Dim intFileNum As Integer ...
    (microsoft.public.access.modulesdaovba)

Loading