Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

I have a text file on a remote server with this content:

-

Line1

Line2

Line3

...

-

I use this code to download it and put each line in a string (array)

Dim WebClient As New System.Net.WebClient
WebClient.Encoding = System.Text.Encoding.ASCII
WebClient.CachePolicy = New System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore)
Dim NewString As String = WebClient.DownloadString("http://www.domain.com/file.txt")
WebClient.Dispose()
Dim MyArray() As String = NewString.Split(vbNewLine)
For MyLoop As Integer = 0 To MyArray.Length - 1
   MsgBox(MyArray(MyLoop).ToString.Replace(vbNewLine, ""))
Next

It's OK, but when showing each line, the 1st line is OK.

After 2nd line, it applies a vbNewLine/vbCrLf to the beginning of each line.

And I CANNOT remove that, even with .Replace(vbNewLine, "")

How to remove this vbNewLine/vbCrLf from beginning of each line?

Thanks.

  • Leaders
Posted (edited)

Edit: Nevermind. Read ATMA's post on the other forum.

 

It sounds like the best idea is to use the String.Trim function. You can specify a set of characters that you want trimmed, in this case carriage-return and line-feed.

   ' There are the line ending characters we don't want in our strings (LF and CR)
   Public Shared ReadOnly LineEndChars As Char() = {ChrW(10), ChrW(13)}

   ' This function removes line ending characters from a string
   Function Example(ByVal text As String) As String
       Return text.Trim(LineEndChars)
   End Function
Edited by snarfblam
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...