VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • 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);


相关教程