Use regular expression to parse lines in a CSV to allow embedded commas:
VB:
While Not sr.EndOfStream
Dim matches As MatchCollection = Regex.Matches(sr.ReadLine(), "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)")
For Each match As Match in matches
Dim sItem As String = match.Group(0).Value
Next
End WhileC#:
while (!sr.EndOfStream){
MatchCollection matches = Regex.Matches(sr.ReadLine(), "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)");
foreach(Match match in matches){
string sItem = match.Group[0].Value;
}
}
0 comments:
Post a Comment