C#教程
C#控制语句
C#函数
C#数组
C#面向对象
C#命名空间和异常
C#文件IO
C#集合
C#多线程
C#其它

C# String Replace()

C# String Replace()

C# Replace() 方法用于获取一个新字符串,其中该字符串中所有出现的指定 Unicode 字符都被替换为另一个指定的Unicode 字符。
Replace() 方法有两种方法。您也可以替换字符串。

签名

public string Replace(Char first, char second)
public string Replace(String firstString, String secondString)

参数

first: 是char类型的第一个参数。
second: 它是char类型的第二个参数。

返回

它返回一个字符串。

C# String Replace() 方法示例

using System; 
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
           string s1 = "Hello F#";
           string s2 = s1.Replace('F','C');
           Console.WriteLine(s2);
        }  
    }  
输出:
Hello C#

C# String Replace() 方法示例 2

using System; 
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
           string s1 = "Hello C#, Hello .Net, Hello lidihuo";
           string s2 = s1.Replace("Hello","Cheers");
           Console.WriteLine(s2);
        }  
    }  
输出:
Cheers C#, Cheers .Net, Cheers lidihuo
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4