You are using Substring method wrongly. Here we go:
Substring has two overloads :
Overload 1: Substring(int Starteindex)
- It will take the start index and will return all the characters after the start index
e.g.
class Program
{
static void Main()
{
string input = "Angel Nursery School; 001";
string sub = input.Substring(6);
Console.WriteLine("Substring: {0}", sub);
}
}
It will return : Nursery School; 001
Overload 2: Substring(int Starteindex, int Endindex)
- It will return all the characters between startindex and Endindex
e.g.
class Program
{
static void Main()
{
string input = "Angel Nursery School; 001";
string sub = input.Substring(6, 13);
Console.WriteLine("Substring: {0}", sub);
}
}
It will return : Nursery
Now coming back to your case. If you want to remove 001, then modify your code as :
String text = ddlschoolname.Text;
String numbers = text;
if (text.Length >= 10)
{
numbers = text.Substring(0, text.Length - 3);
}
Hope this helps.
All the best.