C# Replace字符替換函數


 

 

 它可以將字串內的字符替換為別的字符,可以嵌套使用,如下:

 

 

 需要注意的是,它可以把字符替換為空,但不可以替換空字符,當不確定字符串是否為空時,可以進行以下判斷,再替換:

 

 示例的完整代碼:

string aa="d";
if (aa=="d")
{
Console.WriteLine(aa.Replace("d", "a"));
}

//string b = aa.Replace(".", "").Replace("officeword", "doc").Replace("gw", "other") == "" ? "other" : aa.Replace(".", "").Replace("officeword", "doc").Replace("gw", "other");
// Console.WriteLine(b);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM