Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm building a parser and I have a problem when it comes to string.split().

Dim currentstring As String
currentstring = "'They are running, John','the dogs'" 

When I split the string it will split the commas in between the apostrophes too. Is there any way to get around that so it will only split the ones out side the apostrophes?

String.Split cannot cope with this. You should probably use the Regex class[^].
Share this answer
olivewarbler 14-Jan-12 21:19pm    
I've never used it before, how would you use it for that?
thatraja 15-Jan-12 0:08am    
Agree with Carlo. Check this sample & modify it based on your need.
C# Regex Split - everything inside square brackets[^]
Share this answer
Have you tried this :

string currentstring = "'They are running, John','the dogs'";
string[] result = Regex.Split(currentstring, ",(?=(?:[^']*'[^']*')*[^']*$)");

Extracted from here :[^]
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900