remove blank line from a variable in .net visual basic

Posted on 2012-09-05
Last Modified: 2012-09-05
I create an array and write it to a text file, but it will awalys have a blank line at the end.  How can I fix this?

Dim strNames As String = Nothing
        For Each Names In arrNameList
            strNames = +Names & vbCrLf
        File.WriteAllText("c:\temp\serials.txt", strNames)
        Process.Start("notepad.exe", "c:\temp\serials.txt")
Question by:chadmanvb
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    You can just do:

        Dim strNames As String = String.Join(vbCrLf, arrNameList)
        File.WriteAllText("c:\temp\serials.txt", strNames)
        Process.Start("notepad.exe", "c:\temp\serials.txt")

    Author Comment

    That does not seem to work with an arraylist.  Here is the code to create the array

    Dim arrNameList As New ArrayList

    If ColumnNumber = 0 Then
                    End If

    Should I be using something else?
    LVL 85

    Accepted Solution

    by: initially said "array" so I assumed:

        Dim arrNameList() As String

    Use a List(Of String) instead:

        Dim arrNameList As New List(Of String)

    Then call ToArray() on it:

        Dim strNames As String = String.Join(vbCrLf, arrNameList.ToArray)

    Author Closing Comment

    Perfect!  Thanks so much!  Chad

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now