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