V
vodafone
I've some problems while merging a string retrieved from a stream and
re-built with the encoding.
To be short. The first time string will be concatenated, all works
fine, from the second time, it get only the first string ... the second
part won't never added, and I really don't understand the reason.
Obviously I'm working on vb.net
This is the code.
Dim fi As New FileInfo("g:\x.txt")
Dim mStream As Stream = fi.Open(FileMode.Open, FileAccess.Read)
Dim nBytes As Integer = 256
Dim ByteArray(nBytes) As Byte
Dim [encoding] As System.Text.Encoding = encoding.ASCII
Dim regExp As New Regex("\n")
Dim lastIdx As Int32
Dim ByteRead As Int32 = 0
Dim appo As String = "bye bye "
Dim s As String
Do
ByteRead = mStream.Read(ByteArray, 0, nBytes)
s = appo + [encoding].GetString(ByteArray)
Dim m As Match = regExp.Match(s.ToString)
Do While m.Success
Dim g As Group = m.Groups(0)
Dim tmp As String = (s.Substring(lastIdx, g.Index - lastIdx))
Console.WriteLine(tmp)
lastIdx = g.Index + 1
m = m.NextMatch
Loop
appo = s.Substring(lastIdx)
Loop While (ByteRead > 0)
Somebody can suggest me how to solve, and why my code won't work?
Thanks
Andrea
re-built with the encoding.
To be short. The first time string will be concatenated, all works
fine, from the second time, it get only the first string ... the second
part won't never added, and I really don't understand the reason.
Obviously I'm working on vb.net
This is the code.
Dim fi As New FileInfo("g:\x.txt")
Dim mStream As Stream = fi.Open(FileMode.Open, FileAccess.Read)
Dim nBytes As Integer = 256
Dim ByteArray(nBytes) As Byte
Dim [encoding] As System.Text.Encoding = encoding.ASCII
Dim regExp As New Regex("\n")
Dim lastIdx As Int32
Dim ByteRead As Int32 = 0
Dim appo As String = "bye bye "
Dim s As String
Do
ByteRead = mStream.Read(ByteArray, 0, nBytes)
s = appo + [encoding].GetString(ByteArray)
Dim m As Match = regExp.Match(s.ToString)
Do While m.Success
Dim g As Group = m.Groups(0)
Dim tmp As String = (s.Substring(lastIdx, g.Index - lastIdx))
Console.WriteLine(tmp)
lastIdx = g.Index + 1
m = m.NextMatch
Loop
appo = s.Substring(lastIdx)
Loop While (ByteRead > 0)
Somebody can suggest me how to solve, and why my code won't work?
Thanks
Andrea