1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| internal static void ExtractDelimitedStringToTsl(string s,char fieldsep,char quotesep,bool trim,TStringList tsl)
{ // quotesep=fieldsep : not quoted input
// input tsl is cleared
tsl.Clear();
string word = "";
bool quoteson = false;
for (int i=0;i<s.Length;i++)
if (quoteson)
{
if (s[i]==quotesep)
{
if (i < s.Length - 1 && s[i + 1] == quotesep) { word += quotesep; i++; }
else quoteson = false;
}
else word+=s[i] ;
}
else
if (s[i]==fieldsep)
{
if (trim) tsl.Add(word.Trim()) ; else tsl.Add(word) ;
word="" ;
}
else if (s[i]==quotesep) quoteson=true ;
else word+=s[i] ;
if (trim) tsl.Add(word.Trim()) ; else tsl.Add(word) ;
} |