Initial Commit
This commit is contained in:
29
MarketData/MarketDataLib/CSVHelper/StringParser.cs
Executable file
29
MarketData/MarketDataLib/CSVHelper/StringParser.cs
Executable file
@@ -0,0 +1,29 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user