the characters with the exact values 0 through 9 must be removed from the string. They are not replaced with other characters but entirely removed.
using System;
using System.Text.RegularExpressions;
class Program
{
/// <summary>
/// Remove digits from string.
/// </summary>
public static string RemoveDigits(string key)
{
// Part 2: use Regex.Replace with a metacharacter, and replace with an empty string.
return Regex.Replace(key, @
"\d",
"");
}
static void Main()
{
// Part 1: remove the digits in these example input strings.
string input1 =
"Dot123Net456Perls";
string input2 =
"101Dalmatations";
string input3 =
"4 Score";
string value1 = RemoveDigits(input1);
string value2 = RemoveDigits(input2);
string value3 = RemoveDigits(input3);
Console.WriteLine(value1);
Console.WriteLine(value2);
Console.WriteLine(value3);
}
}
DotNetPerls
Dalmatations
Score