2

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 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! now all my numbers are wrong but I expected that. Works perfectly.
2

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

Comments

1

Another alternative I often find useful is this:

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

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.