How to get the last number from a String in C#
To get the last number from a string, we can use the Split(' ')
method in C#.
Here is an example that gets the last number 1
from a following string:
using System;
class LastNumber {
static void Main() {
string name = "Hello 1";
string[] words = name.Split(' ');
Console.WriteLine(words[words.Length - 1]);
}
}
Output:
1