Re: String builder (Parsing vertically presented records)
- From: "Cerebrus" <zorg007@xxxxxxxx>
- Date: 14 Mar 2006 01:01:06 -0800
Hi,
Another implementation :
===================
Private Sub ReadText()
Dim fsr As New FileStream("VertFile.txt", FileMode.Open,
FileAccess.Read)
Dim fsw As New FileStream("ResultFile.txt", FileMode.Create,
FileAccess.Write)
Dim sr As New StreamReader(fsr)
Dim sw As New StreamWriter(fsw)
Dim thisLine As String
Dim lineContents() As String
'Ignore the first line of the text file
sr.ReadLine()
While sr.Peek > -1
thisLine = sr.ReadLine()
lineContents = thisLine.Split(New Char() {" "c})
If lineContents(1).Trim = "NewRegID" Then
'We have a new record. Write current value of sb and Insert new
line.
If sb.Length > 0 Then
'Replace the last comma with a period.
sb.Replace(",", ".", sb.Length - 1, 1)
sw.WriteLine(sb.ToString())
End If
sb = New StringBuilder()
sb.Append(lineContents(0))
sb.Append(",")
Else
'This is the same record. Keep adding text
sb.Append(lineContents(1))
sb.Append(",")
If sb.Length > 2 Then
sb.Append(lineContents(2))
sb.Append(",")
End If
End If
End While
'Replace the last comma with a period.
sb.Replace(",", ".", sb.Length - 1, 1)
sw.WriteLine(sb.ToString())
sw.Flush()
'Clean up
sw.Close()
sr.Close()
fsr.Close()
fsw.Close()
End Sub
===================
Note that your third set of records (213565432) does not have the line
"NewRegID".
When that line is inserted in the sample text, then it works.
Regards,
Cerebrus.
.
- Prev by Date: Re: Distributing Application / SQL Server Express question
- Next by Date: Re: VSTO 2005 - Read Range from excel
- Previous by thread: Re: String builder (Parsing vertically presented records)
- Next by thread: Re: String builder (Parsing vertically presented records)
- Index(es):
Relevant Pages
|
Loading