vb.net code for inserting vbcrlf every 80 characters

T

tom.krier

Here's the thing. I am downloading a tiff image through an http
stream, then I am converting it to a byte array, then I convert it to a
string which I place in an XML file. When I place the string in the
xml file it is super long (slows down all editors when opening), so I
was thinking to insert vbCrLf every 80 characters or so but I don't
want to slow down my program that creates the XML file. I was
wondering the best way to accomplish that. Here is my current code:

xmlWriter.WriteString(getBase64Document(loan))

Private Function getBase64Document(ByVal loan As MtgLoan) As String
Dim httpStream As System.Net.WebClient = New Net.WebClient()
Dim bytes As Byte() =
httpStream.DownloadData(loan.ICMBASE(0).resourceObject.URL.value) 'This
pulls in the image as a byte()
Dim base64String As String = Convert.ToBase64String(bytes)

Return base64String
End Function
 
R

Rob MacFadyen

Tom,

I'm more C# than VB... but I did do a lot of VB6 so I'll just wing it
(strings in vb.net begin at 0... right?):

Dim i as Integer
Dim f as String

f = ""
For i = 0 to len(Base64String) - 1 step 80 :
f = f & mid(Base64String, i, 80) & vbCrLf
Next i


Regards,

Rob
 
R

Rob MacFadyen

Tom,

My previous message... I was doing simple concatenation... "f = f & mid(f,
...) & f"... well that really should be done using a string builder. String
builder is much more efficient than regular strings for this exact sort of
algorithm.

Doh!!

Regards,

Rob
 
T

tom

Okay I actually changed my code so that it processes even quicker now.
I would still like vbCrLf every 80 characters or so, and I tried a
couple methods and they are super slow. Any other ideas on a quick
running solution? Here is the code I use now...
Dim httpStream as system.net.webclient = new net.webclient()
dim bytes as byte() =
httpstream.downloaddata(loan.icmbase(0).resourceobject.URL.value)
xmlWriter.WriteBase64(bytes, 0, bytes.Length)

So now instead of sticking it in a string I buffer it from bytes
straight to file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top