How to replace number from a string in C#

Category > CSHARP || Published on : Wednesday, November 18, 2015 || Views: 11229 || How to replace number from a string in C# replace number from a string in C#


Introduction

Here Pawan Kumar If we have a string that contains letters and numbers and we want to remove all the numbers from that particular string. What we have to do is to use regex to remove all numbers.will explain how to

Description

In previous post I have explained SQL Server Execute Stored Procedure from Another Stored Procedure with Parameters, Create table from json jQuery with detailed example, How to Store Hashtable in Session using asp.net and C# with example, Zoom Feature for Query Text and Results Text in SQL Server Management Studio 2012, How to make How to make blinking/flashing text with CSS3 and jQuery, Format JSON Date String To Local DataTime Object Using JavaScript, and many more articles.

Now I will explain How to How to replace number from a string in C#

So follow the steps to learn How to replace number from a string in C#

Consider following string variable

String Strvalue = "string12";

and we need to take out the number 12 from variable "Strvalue".to do this we can use C# Regex class.

Below is the code to achieve this.

Strvalue = Regex.Replace(sortdatafield, @"[\d-]", string.Empty);

Once you will run the code, you will get a new value without numbers.

I hope you have enjoyed and find useful.

Conclusion:

So, In this tutorial we have learned, How to replace number from a string in C#