usvpn Posted April 2, 2012 Posted April 2, 2012 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. Quote
Leaders snarfblam Posted April 2, 2012 Leaders Posted April 2, 2012 (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 April 2, 2012 by snarfblam Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.