0
string num = Console.ReadLine();

string a="";
string b="";
for (int i = num.Length; i > 0; i--)
{
    if (num[i] =='-')
    {
        break;
    }
    else
    {
        b +=num[i].ToString();
    }
}

//then reverse b 
//a=num-(b.lenght+1);
Console.WriteLine(b);``

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in number_spliter.exe

Additional information:

Index was outside the bounds of the array.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

2

Arrays start at index zero

for (int i = num.Length-1; i >= 0; i--)
epascarello
  • 204,599
  • 20
  • 195
  • 236