设置一个字符串-
string str = "Bit and Bat";
假设您需要将B和t内的内容替换为A并大写完整的字符串。为此,请使用Replace-
Regex.Replace(str, "B.t", "BAT");
让我们看完整的代码-
using System;
using System.Text.RegularExpressions;
namespace Demo {
class Program {
static void Main(string[] args) {
string str = "Bit and Bat";
Console.WriteLine(str);
string res = Regex.Replace(str, "B.t", "BAT");
Console.WriteLine(res);
}
}
}输出结果
Bit and Bat BAT and BAT