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

VB
Dim currentstring As String
currentstring = "'They are running, John','the dogs'" 
currentstring.split(",")


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?
Posted

String.Split cannot cope with this. You should probably use the Regex class[^].
 
Share this answer
 
Comments
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    
5!
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 :

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


Extracted from here :
http://stackoverflow.com/questions/3147836/c-sharp-regex-split-commas-outside-quotes[^]
 
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