How to retrieve integer value and remove all other strings in C# ?


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.

If you want to retrieve the integer value and remove all other strings in C# , one can use the Regex.Replace method and apply regular expression easily and get only the integer part from a string.

How to How to retrieve integer value and remove all other strings in C# ?

Below is a sample sourecode demonstrating How to retrieve integer value and remove all other strings in C# ?

string inputData = "AbundantCode-001";

var data = Regex.Replace(inputData, "[^0-9]+", string.Empty);

Note : You need to include the using System.Text.RegularExpressions namespace to the code behind file. The Regex class is defined in the System.Text.RegularExpressions namespace.


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: