使用StringBuilder替换字符串
设置一个字符串-
StringBuilder str =新字符串Builder("Fitness is important");使用Replace()方法替换字符串-
str.Replace("important", "essential");以下是使用StringBuilder替换字符串的代码-
示例
using System;
using System.Text;
class Demo {
static void Main() {
//初始字符串
StringBuilder str =新字符串Builder("Fitness is important");
Console.WriteLine(str.ToString());
//替换
str.Replace("important", "essential");
//新字符串
Console.WriteLine(str.ToString());
Console.ReadLine();
}
}输出结果
Fitness is important Fitness is essential
热门推荐
10 婚礼美句简短祝福语
11 给老板祝福语简短精辟
12 经典祝福语简短情侣句子
13 租房明天搬家祝福语简短
14 酒店客人祝福语简短
15 小红书生日祝福语简短
16 兔年祝福语简短100字
17 60岁长辈祝福语简短
18 朋友弟弟生日祝福语简短