public class StringUtil
{
private StringUtil()
{
}
///
/// Splits a string on the delimiter. Ignores chars within "".
///
/// the string to split
/// the delimiter to find
///
public static string[] Split(string str,char delimiter)
{
ArrayList ret=new ArrayList();
int pos=FindNextDelimiter(str,delimiter);
string left=str;
while(pos>-1)
{
ret.Add(left.Substring(0,pos));
if(pos+1<=left.Length)left=left.Substring(pos+1);
pos=FindNextDelimiter(left,delimiter);
}
ret.Add(left); //add what is left
return (string[])ret.ToArray(typeof(string));
}
private static int FindNextDelimiter(string str, char delimiter)
{
int pos=-1;
bool inQuote=false;
bool found=false;
for(int i=0;i
if(str[i].Equals('"'))
{
inQuote=!inQuote;
}
if(str[i]==delimiter && !inQuote)
{
pos=i;
found=true;
}
}
return pos;
}
}