///
/// 以逗號拆分字符串
/// 若字段中包含逗號(備注:包含逗號的字段必須有雙引號引用)則對其進行拼接處理
/// 最後在去除其字段的雙引號
///
///
///
private static string[] SplitStringWithComma(string splitStr)
{
var newstr = string.Empty;
List
bool isSplice = false;
string[] array = splitStr.Split(new char[] { ',' });
foreach (var str in array)
{
if (!string.IsNullOrEmpty(str) && str.IndexOf('"') > -1)
{
var firstchar = str.Substring(0, 1);
var lastchar = string.Empty;
if (str.Length > 0)
{
lastchar = str.Substring(str.Length - 1, 1);
}
if (firstchar.Equals("\"") && !lastchar.Equals("\""))
{
isSplice = true;
}
if (lastchar.Equals("\""))
{
if (!isSplice)
newstr += str;
else
newstr = newstr + "," + str;
isSplice = false;
}
}
else
{
if (string.IsNullOrEmpty(newstr))
newstr += str;
}
if (isSplice)
{
//添加因拆分時丟失的逗號
if (string.IsNullOrEmpty(newstr))
newstr += str;
else
newstr = newstr + "," + str;
}
else
{
sList.Add(newstr.Replace("\"", "").Trim());//去除字符中的雙引號和首尾空格
newstr = string.Empty;
}
}
return sList.ToArray();
}