C#程序用'%20'替换字符串中的所有空格
我们有一个带空格的示例字符串-
str ="你好,世界!";
使用Replace()C#中的方法将字符串中的所有空格替换为'%20'-
str2 = str.Replace(" ", "%20");示例
您可以尝试运行以下代码,用'%20'替换字符串中的所有空格。
using System;
class Demo {
static void Main() {
String str, str2;
str ="你好,世界!";
Console.WriteLine("String: "+str);
str2 = str.Replace(" ", "%20");
Console.WriteLine("String (After replacing): "+str2);
}
}输出结果
String: 你好,世界! String (After replacing): Hello%20World%20!
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短