30 lines
742 B
C#
30 lines
742 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace MarketData.CSVHelper
|
|
{
|
|
public class StringParser
|
|
{
|
|
private StringParser()
|
|
{
|
|
}
|
|
public static string[] ParseDelimitedString(string arguments, char delim = ',')
|
|
{
|
|
var regex = new Regex("(?<=^|,)(\"(?:[^\"]|\"\")*\"|[^,]*)");
|
|
List<String> values = new List<String>();
|
|
foreach (Match m in regex.Matches(arguments))
|
|
{
|
|
String value = m.Value;
|
|
if (null != value && value.StartsWith("\"") && value.EndsWith("\""))
|
|
{
|
|
value = value.Substring(1, value.Length - 2);
|
|
}
|
|
values.Add(value);
|
|
}
|
|
return values.ToArray();
|
|
}
|
|
}
|
|
}
|