替换字符串中所有空格为 ‘%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