문자열 설정 -
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