General Topics include: .NET Framework
Note: Most posts can be categorized into one of the forums below, where experts on that topic will be able to help you find a solution to your problem faster and more efficiently.

Enjoy an ad free experience by logging in. Not a member yet? Register.
Go Back  Xtreme .NET Talk > .NET > General > vbNewLine or VbCrLf Problem

Thread Tools Display Modes
Old 04-02-2012, 10:26 AM
usvpn usvpn is offline
Join Date: Apr 2010
Posts: 45
usvpn is on a distinguished road
Default vbNewLine or VbCrLf Problem

I have a text file on a remote server with this content:
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("")
Dim MyArray() As String = NewString.Split(vbNewLine)
For MyLoop As Integer = 0 To MyArray.Length - 1
    MsgBox(MyArray(MyLoop).ToString.Replace(vbNewLine, ""))
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?
Reply With Quote
Old 04-02-2012, 05:10 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Ultimate Contributor

Preferred language:
C#, VB
Join Date: Jun 2003
Location: USA
Posts: 2,097
snarfblam will become famous soon enough
Default Re: vbNewLine or VbCrLf Problem

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

Last edited by snarfblam; 04-02-2012 at 05:17 PM.
Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
what is vbCrlf monkmasterflex Visual Basic .NET 13 11-09-2009 03:12 PM
vbCrLf Replacement JDYoder General 14 08-16-2005 10:36 AM
Visual Basic 6, vbcrlf problem flexpress Windows Forms 1 09-04-2003 01:38 PM
vbcrlf LostInSpace General 6 06-02-2003 06:04 PM


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..