[Solved] C# read only part of whole string [closed]


You can split the string on / and then use int.TryParse on the first element of array to see if it is an integer like:

string str = "1234/xxxxx";
string[] array = str.Split(new []{"https://stackoverflow.com/"}, StringSplitOptions.RemoveEmptyEntries);
int number = 0;
if (str.Length == 2 && int.TryParse(array[0], out number))
{
    //parsing successful. 
}
else
{
    //invalid number / string
}

Console.WriteLine(number);

solved C# read only part of whole string [closed]