替換字串中所有空格為 ‘%20’ 的 C# 程式
我們有一個包含空格的示例字串 −
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!
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP