• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

remove blank line from a variable in .net visual basic

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
        Next
        File.WriteAllText("c:\temp\serials.txt", strNames)
        Process.Start("notepad.exe", "c:\temp\serials.txt")
0
chadmanvb
Asked:
chadmanvb
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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")
0
 
chadmanvbAuthor Commented:
Idle,
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
                                        arrNameList.Add(ds.Tables(0).Rows(RowNumber)(ColumnNumber).ToString())
                End If

Should I be using something else?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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)
0
 
chadmanvbAuthor Commented:
Perfect!  Thanks so much!  Chad
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now