zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    KMP算法的理解和代码实现
    关于线程死锁
    PAT1018
    PAT1059
    PAT1009
    PAT1006
    PAT1005
    PAT1004
    PAT1002
    PAT
  • 原文地址:https://www.cnblogs.com/myka/p/11988524.html
Copyright © 2011-2022 走看看