format #region format
private string formatString =string.Empty;
private int index = 0;
private StringBuilder sbword = new StringBuilder();
char[] splitc = new char[]{' ','\t','\r','\n'};//',','=',
char[] splituse = new char[]{',','='};
private bool Insplitc(char[] splitc,char c)
{
for(int i=0;i<splitc.Length;i++)
{
if(c==splitc[i])
return true;
}
return false;
}
private char Peek()
{
return Peek(1);
}
private char Peek(int i)
{
if(index+i>=formatString.Length)
return '\0';
return formatString[index+1];
}
/**//// <summary>
/// 返回一个字符组,关键字或是 变量 或是字符串
/// </summary>
/// <returns></returns>
private string GetAWord()
{
sbword.Remove(0,sbword.Length);
int oldindex = index;
char c;
char pc;
//跳过空白
for(;index<formatString.Length;index++)
{
if(!Insplitc(splitc,formatString[index]))
break;
}
oldindex =index;
for(;index<formatString.Length;index++)
{
pc = Peek();
c= formatString[index];
if(Insplitc(splitc,c))
break;
if(Insplitc(splituse,c))
{
break;
}
}
if(oldindex<index)
return formatString.Substring(oldindex,index-oldindex);
else// if(oldindex==index)
{
if(index<formatString.Length)
return formatString[index++].ToString();
else
return "\n";
}
}
#endregion
下载源代码