I have a problem at the line String fromIndexString = topStiva.Substring(topStivaLength + 1, topStiva.Length); . I shows that topStiva.Length is out or range.
The code is as follows:
String actiuneRezultata(String topStiva, String cuvIntr) {
int index = -1;
String primulCharCuvIntr = cuvIntr.Substring(0, 1);
if (primulCharCuvIntr.Equals("+") == true)
primulCharCuvIntr = "\\" + primulCharCuvIntr;
else
if (primulCharCuvIntr.Equals("*") == true)
primulCharCuvIntr = "\\" + primulCharCuvIntr;
else
if (primulCharCuvIntr.Equals("*") == true)
primulCharCuvIntr = "\\" + primulCharCuvIntr;
else
if (primulCharCuvIntr.Equals("*") == true)
primulCharCuvIntr = "\\" + primulCharCuvIntr;
else
if (primulCharCuvIntr.Equals("*") == true)
primulCharCuvIntr = "\\" + primulCharCuvIntr;
for (int i = 0; i < ta.Length; i++) {
if (ta[i].CompareTo(primulCharCuvIntr) == 0) {
index = i;
break;
}
}
int topStivaLength = topStiva.Length - 1;
while (topStiva[topStivaLength] >= '0' && topStiva[topStivaLength] <= 9)
topStivaLength--;
String fromIndexString = topStiva.Substring(topStivaLength + 1, topStiva.Length);
int fromIndex = int.Parse(fromIndexString);
if (index < 0)
return "Nu face parte din gramatica!";
else
return tabela[fromIndex][index];
}
The value topStiva is gets it from the call actiuneRezultata(stivaAPD.Peek().ToString(), another_value)
I saw that in stivaAPD I am geeting after push some values. So why is it that is out of range? Pls help!
The second argument to
String.Substringis the length of the desired substring. You seem to be calling it as if it were instead the (exclusive) end index of the substring. Try calling the following so that your length is equal to the distance to the end index of the string.