Click here to Skip to main content
Click here to Skip to main content
Alternatives (4)

Tagged as

Convert Vertical List to String Array

, 24 Sep 2010 CPOL

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

24 Sep 2010
Ron Beyer
You may want to take a look at String.Join:Your code can be compressed to:Dim str as Stringstr = Chr(34) + String.Join(Chr(34) + "," + Chr(34), arr) + Chr(34)(My VB skills are a bit lacking, so the syntax may be a bit off, but you get the idea).
24 Sep 2010
jlabrou
Check this out: Dim z = String.Join(",", txt.SelectedText.Split(Chr(10)))
27 Sep 2010
Alan Burkhart
I'd never used String.Join before. Didn't even know it was there. :laugh: However, part of the idea is to skip all empty lines AND not end up with an empty string at the end (which my first code didn't address) AND insert the quotes. To get all this done with String.Join, it still took 8...
6 Oct 2010
Prerak Patel
Pretty simple to ignore blank entries..Dim s As String = """" & String.Join(""",""", txt.SelectedTextt.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)) & """"

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...

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