Learn how to a build a cloud-first strategyRegister Now


remove blank line from a variable in .net visual basic

Posted on 2012-09-05
Medium Priority
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
  • 2
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38369073
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

ID: 38369162
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 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 38369183
Gotcha...you 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

ID: 38369212
Perfect!  Thanks so much!  Chad

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 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