views:

1788

answers:

4

Trying to split a line wherever "," appears (with the quotation marks), The problem is VB.NET uses " to start/end strings, so I tried using .Split(""",""") but that then splits it by " not ","

+4  A: 

Try something like this:

Dim TestToSplit As String = "Foo"",""Bar"
Dim Splitted() As String = TestToSplit.Split(New String() {""","""}, StringSplitOptions.None)

I just tested it and got an array with Foo And Bar. I hope this helps.

Jon
Perfect! now all my numbers are wrong but I expected that. Works perfectly.
Hintswen
A: 

To escape the "-character in VB.NET, use two: ""

Phoexo
A: 

The Split function (the way you are using it) expects a Char. If you want to split on multiple characters you need to use a string array. (Seems to me another overload of a single string value would have been handy.)

This function splits a line of text and returns an array based on the delimiter you have specified. (Of course, you could make this more general purpose by passing in the separator array.)

   Private Function SplitLine(ByVal lineOfText As String) As String()

      Dim separator() As String = {""","""}
      Dim result() As String

      result = lineOfText.Split(separator, StringSplitOptions.None)

      Return result

   End Function
Bill
+1  A: 

Another alternative I often find useful is this:

Regex.Split(textToSplit, """,""")

Lets you split on more complex criteria than an array of alternative separators.

Christian Hayter