string[] SplitLine(string line)
{
string[] infos = line.Split(new char[] { ',' });
infos = RServerUtility.MergeDoubleQuotesToOne(infos);
return infos;
}
public static string[] MergeDoubleQuotesToOne(string[] orgs)
{
List<string> mergeStrings = new List<string>();
if (orgs == null || orgs.Length <= 0)
{
return mergeStrings.ToArray();
}
int count = orgs.Length;
for (int i = 0; i < count; i++)
{
if (orgs[i].Length > 0 && orgs[i].TrimStart()[0] == '"')
{
orgs[i] = orgs[i].TrimStart();
if (orgs[i].TrimEnd()[orgs[i].TrimEnd().Length - 1] == '"')
{
orgs[i] = orgs[i].TrimEnd();
if (!string.IsNullOrEmpty(orgs[i]) && orgs[i].Length != 1)
{
orgs[i] = orgs[i].Remove(0, 1);
orgs[i] = orgs[i].Length > 0 ? orgs[i].Remove(orgs[i].Length - 1, 1) : orgs[i];
mergeStrings.Add(orgs[i]);
continue;
}
}
while (true)
{
if (i < orgs.Length)
{
orgs[i] = orgs[i] + "," + orgs[i + 1];
for (int k = i + 1; k < orgs.Length - 1; k++)
{
orgs[k] = orgs[k + 1];
}
count--;
if (count <= i)
{
break;
}
if (orgs[i][orgs[i].Length - 1] == '"')
{
orgs[i] = orgs[i].TrimEnd();
orgs[i] = orgs[i].Remove(0, 1);
orgs[i] = orgs[i].Length > 0 ? orgs[i].Remove(orgs[i].Length - 1, 1) : orgs[i];
mergeStrings.Add(orgs[i]);
break;
}
}
}
}
else
{
mergeStrings.Add(orgs[i]);
}
}
return mergeStrings.ToArray();
}