C#中使用正则表达式 官网
在C#中使用正则表达式,可进行字符串的匹配、替换等操作。 // 示例2:替换字符串中的数字为*号using System;using System.Text.RegularExpressions;class Program { static void Main() { string input = "abc123"; string result = Regex.Replace(input, @"\d", "*"); Console.WriteLine(result); // 运行结果:abc*** }} 通过不同的模式和方法,能实现多样的字符串处理。 在进行替换操作时,要确保模式准确匹配需替换的内容。