Replace() 메서드를 사용하여 문자를 별표로 바꿉니다.
문자열이 −
라고 가정해 보겠습니다.string str = "dem* text";
교체하려면 Replace() 메서드를 사용하십시오 -
str.Replace('*', 'o'); 다음은 전체 코드입니다 -
예
using System;
public class Program {
public static void Main() {
string str = "dem* text";
Console.WriteLine("Initial string = " + str);
string res = str.Replace('*', 'o');
// after replacing
Console.WriteLine("After replacing asterisk = " + res.ToString());
}
} 출력
Initial string = dem* text After replacing asterisk = demo text