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

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.

%d bloggers like this: