Replacing only characters using Regex in string C#
How to get only letters from a string in C#.
using System; using System.Text.RegularExpressions; public class Program { public static void Main() { Console.WriteLine("Replacing only characters using Regex in string C#\n"); string sampleText = "I like .NET 4.5. This is awesome."; //find all characters that are letters Regex regex = new Regex("[a-zA-Z]"); sampleText = regex.Replace(sampleText, "$"); Console.WriteLine(sampleText); } }DEMO
Replacing only characters using Regex in string C#
Reviewed by Bhaumik Patel
on
3:53 AM
Rating: