Home All Groups Group Topic Archive Search About

vb.net code for inserting vbcrlf every 80 characters

Author
8 Sep 2006 5:23 PM
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

Author
9 Sep 2006 8:29 PM
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

<tom.kr***@gbmail.com> wrote in message
Show quoteHide quote
news:1157736203.517822.40020@b28g2000cwb.googlegroups.com...
> 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
>
Are all your drivers up to date? click for free checkup

Author
9 Sep 2006 8:31 PM
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
<tom.kr***@gbmail.com> wrote in message
Show quoteHide quote
news:1157736203.517822.40020@b28g2000cwb.googlegroups.com...
> 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
>

Bookmark and Share