I would like to do a parser in c# that return the command et the params in a string[]. The initial command comes from a textbox it goes like this :
You type something like this :
*****
Add(param1,param2)
*****
and it is supposed to return something like this :
*****
"Add","param1","param2"
*****
so i can use it after, but i have a
System.IndexOutOfRangeException
What's wrong with that code???
private void Parse()
{
string[] Commande=ObtenirCode(this.Tb1.Lines[this.Tb1.Lines.Length-1]);
//Using string[] here to do the command "effect"
}
private string[] ObtenirCode(string LigneCode)
{
System.Text.RegularExpressions.Regex Parse=new Regex(@"^((?:[a-z0-9])*)\s*(?:\(|\s+)\s*((?:[a-z0-9])*)\s*(?:(?:,|\s+)\s*([a-z0-9]*)\s*)*\s*(?:\)|\);)?$",RegexOptions.IgnoreCase);
Match Line=Parse.Match(LigneCode);
if(!(Line.Groups.Count>255) && !(Line.Groups.Count<1))
{
byte Dmn=2;
if(Line.Groups.Count==3)
{
Dmn+=(byte)Line.Groups[3].Captures.Count;
}
string[] Resultat=new String[Dmn];
Resultat[0]=Line.Groups[1].ToString();
Resultat[1]=Line.Groups[2].ToString();
CaptureCollection CC=Line.Groups[3].Captures;
for(byte j=0;j<CC.Count;j++)
{
Resultat[j+2]=CC[j].ToString(); //It says the mistake is around here//
}
return Resultat;
}
else
{
this.Tb1.Text="Error!, The number or parameters should be between 1 & 255.";
string[] Resultat={"Error","Error"};
return Resultat;
}
}
I know the mistake is probably a stupid thing, but i'm anewbie in c# and i wanna know what to do. Thank you.