C# 程序用“%20” 替换字符串中的所有空格
我们有一个带有空格的字符串样本 −
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