Click here to Skip to main content
Click here to Skip to main content

Tagged as

Convert Vertical List to String Array

, 24 Sep 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
This converts a vertical list to a comma-delimited list with each entry enclosed in double quotes.
 
With a vertical list in a textbox, just select the lines to convert and call the code from a toolstrip button. Conversion is very fast. It ignores blank lines within the list, but will tack on an extra comma if you select a blank line below the last list entry.
 
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
  myStr = String.Empty
  Dim arr() As String = txt.SelectedText.Split(Chr(10))
  For l = 0 To arr.Length - 1
    If arr(l).Length > 0 Then
      myStr &= Chr(34) & arr(l) & Chr(34)
      If l < arr.Length - 1 AndAlso arr(l).Length > 0 Then
        myStr &= ","
      End If
    End If
  Next
  txt.SelectedText = myStr
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alan Burkhart

United States United States
I'm not an IT guy. Programming has been a hobby for me (and occasionally useful) ever since a sister in-law introduced me to a TI-99 4/A about a million years ago.
 
The creative challenge is relaxing and enjoyable. As such, I'd never mess up a fun hobby by doing it for a living.
 
Now, if I can just get Code Project to add "Truck Driver" to the list of job titles in the profiles...

Comments and Discussions

 
GeneralReason for my vote of 3 A useful operation, but not the most... PinmemberCIDev7-Oct-10 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 24 Sep 2010
Article Copyright 2010 by Alan Burkhart
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid