mein Programm versucht, spezielle Formel (siehe die Beispiele) in explicited one.there sind einige Begriffe, die die Färmula stehen muss: -there ist kein Leerzeichen ("") in Die ganze Formel -it Formel hat nur gerundete Klammern "(,)" und nicht alle Klammern bilden "{} []" -Die Formel enthält nur Buchstaben (az, AZ), Ziffern (auch Zahlen) und gerundete Klammern . -für jede Öffnungshalterung muss eine geeignete Schließhalterung vorhanden sein. -zur Formel darf nicht mit Klammern beginnen.extend und Figur speziell behandelte Formel
hier sind einige Beispiele: * input: 'abz2 (3 (a) 2 (ab)) a Ausgang:' abzaaaababaaaababa
- input: ‚a2 (A) 6 (g2 (a))‘ output: 'aAAgagagagagaga'
here und der Code:
bool ExistBrackets(string st)
{
for (int i = 0; i < st.Length; i++)
{
if (IsBracket(st[i]))
return false;
}
return true;
}
string AddChainDeleteBracks(int open, int close, string input)
{
string to="",from="";
//get the local chain multipule the number in input[open-1]
//the number of the times the chain should be multiplied
for (int i = input[open - 1]; i > 0; i--)
{
//the content
for (int m = open + 1; m < close; m++)
{
to = to + input[m];
}
}
//get the chain i want to replace with "to"
for (int j = open - 1; j <= close; j++)
{
from = from + input[j];
}
String output = input.Replace(from, to);
return output;
}
private void PopulateStartEnd()
{
//assuming that start and end are empty
int cS=0,cE=0;
//populate start
for (int i = 0; i < (textBox1.Text.Length); i++)
{
if (textBox1.Text[i] == '(')
{
start[cS] = i;
cS++;
}
if (textBox1.Text[i] == ')')
{
end[cE] = i;
cE++;
}
}
}
private string FigureInput(string st)
{
int i,close;
PopulateStartEnd();
//get the index in the start array which is populated
for (i = start.Length - 1; start[i] != 0; i--) ;
//populate the last letters if there is outside the brackets
while (!ExistBrackets(st))
{
//loop on the latest opening brackets in start array
for (; i >= 0; i++)
{
//find the suitable closing brackets in the end array
for (close = 0; ((end[close] > start[i]) && (end[close] != null)); close++) ;
st=AddChainDeleteBracks(i, close, st);
}
}
return st;
}
die wichtigste Methode ist FigureInput
der Fehler i erhalten:
** * ** Ausnahmetext ** * **** -System. IndexOutOfRangeException: Index befand sich außerhalb der Grenzen des Arrays. bei myProject.Formula.PopulateStartEnd() in C: \ Projekte_2012 \ Project_Noam \ Project \ myProject \ myProject \ Formula.cs: Zeile 156 bei myProject.Formula.FigureInput (String st) in C: \ Projects_2012 \ Project_Noam \ Project \ myProject \ myProject \ Formula.cs: Linie 135 bei myProject.Formula.generateButton_Click (Object sender, EventArgs e) in C: \ Projects_2012 \ Project_Noam \ Project \ myProject \ myProject \ Formula.cs: Linie 36
Haben Sie die Werte der verschiedenen Zeichenfolgen an dem Punkt überprüft, an dem die Ausnahme ausgelöst wurde? Sind die Stringlängen korrekt? Sind die Arrays 'start' und' end' mit der richtigen Größe initialisiert? – Oded
Anfang und Ende sind in der gleichen Größe, aber nicht alle Zellen sind belegt. meinst du auf die Eingabezeichenfolge? – Noam650
Könnte auch die Eingabezeichenfolge sein. Die Ausnahme gibt an, dass Sie entweder versuchen, auf einen Index zuzugreifen, der nicht existiert - in "textBox1.Text", "start" oder "end" (prüfen Sie die Werte von "i", "cS" und "cE") 'wenn die Ausnahme auftritt und vergleichen Sie mit der 'Länge' der verschiedenen Arrays. – Oded