65.9K
CodeProject is changing. Read more.
Home

Convert Vertical List to String Array

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Sep 27, 2010

CPOL
viewsIcon

7090

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

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 lines instead of 10 in the original. There should be a way to get it done with only a couple lines of code, I'm thinking.
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
  myStr = Chr(34) & String.Join(Chr(34) & "," & Chr(34), txt.SelectedText.Split(Chr(10)))
  myStr = myStr.Replace("," & Chr(34) & Chr(34), String.Empty)
  If myStr.EndsWith("," & Chr(34)) Then
    myStr = myStr.Substring(0, myStr.Length - 2)
  ElseIf Not myStr.EndsWith(Chr(34)) Then
    myStr &= Chr(34)
  End If
  txt.SelectedText = myStr

End Sub