【问题标题】:C# string manipulation search and replaceC# 字符串操作搜索和替换
【发布时间】:2010-09-10 19:05:52
【问题描述】:

我有一个字符串,其中包含< tag > 形式的标签。有没有一种简单的方法可以用特殊的 ascii 字符以编程方式替换这些标签的实例?例如将 "< tab >" 之类的标签替换为 '/t' 的 ascii 等效项?

【问题讨论】:

    标签: c# regex string


    【解决方案1】:
    string s = "...<tab>...";
    s = s.Replace("<tab>", "\t");
    

    【讨论】:

      【解决方案2】:
      using System.Text.RegularExpressions;
      
      Regex.Replace(s, "TAB", "\t");//s is your string and TAB is a tab.
      

      【讨论】:

        【解决方案3】:
        public static Regex regex = new Regex("< tab >", RegexOptions.CultureInvariant | RegexOptions.Compiled);
        public static string regexReplace = "\t";
        string result = regex.Replace(InputText,regexReplace);
        

        【讨论】:

          【解决方案4】:

          正则表达式模式应该可以解决问题。

          【讨论】:

          • 我是 Expresso ultrapico.com 的忠实粉丝,可以指导我度过难关。
          猜你喜欢
          • 1970-01-01
          • 2018-01-02
          • 2014-02-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多