by @codeexamples

How to get the last number from a String in C#

Home » c-sharp » 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:

using System;

class LastNumber {
  static void Main() {
      string name = "Hello 1";
      string[] words = name.Split(' ');
      Console.WriteLine(words[words.Length - 1]);
  }
}

Output:

1