공백이 있는 샘플 문자열이 있습니다. −
str ="Hello World !";
C#의 Replace() 메서드를 사용하여 문자열의 모든 공백을 '%20' -
으로 바꿉니다.str2 = str.Replace(" ", "%20"); 예시
다음 코드를 실행하여 문자열의 모든 공백을 '%20'으로 바꿀 수 있습니다.
using System;
class Demo {
static void Main() {
String str, str2;
str ="Hello World !";
Console.WriteLine("String: "+str);
str2 = str.Replace(" ", "%20");
Console.WriteLine("String (After replacing): "+str2);
}
} 출력
String: Hello World ! String (After replacing): Hello%20World%20!