【问题标题】:Visual Studio: show all special characters in a stringVisual Studio:显示字符串中的所有特殊字符
【发布时间】:2014-07-16 02:25:10
【问题描述】:

在调试时,Visual Studio 不会在字符串中显示某些特殊字符。大多数人都熟悉 notepad++ 显示特殊字符的方式(从另一篇文章中复制):

更具体地说,我的字符串包含字符代码为 30 的记录分隔符。Notepad++ 将其显示为 [RS]。 Visual Studio 根本不显示它。所以像hello[RS]stackoverflow[RS]1[RS]2 这样的字符串就变成了hellostackoverflow12。更糟糕的是,如果字符串以“不可见”字符结尾,则无法注意到这一点,因为字符串看起来仍然合理。我希望能够在调试模式下、将鼠标悬停在字符串上以及在监视窗口中查看所有字符。

【问题讨论】:

    标签: visual-studio-2010 settings special-characters


    【解决方案1】:

    使用正则表达式找出字符串中的特殊字符

    static void Main(string[] args)
    {
        string str = "Th!s $tri^g c@n$ist $pecial ch@rs";
        Match match = Regex.Match(str, "[^a-z0-9]",
                RegexOptions.IgnoreCase);
        while (match.Success)
        {
            string key = match.Value;
            Console.Write(key);
            match = match.NextMatch();
        }
        Console.ReadLine();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 2019-08-31
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多