C# How to replace Microsoft's Smart Quotes with straight quotation marks?

后端 未结 12 1441
花落未央
花落未央 2020-12-08 00:50

My post below asked what the curly quotation marks were and why my app wouldn\'t work with them, my question now is how can I replace them when my program comes across them,

12条回答
  •  悲&欢浪女
    2020-12-08 01:32

    When I encountered this problem I wrote an extension method to the String class in C#.

    public static class StringExtensions
    {
        public static string StripIncompatableQuotes(this string s)
        {
            if (!string.IsNullOrEmpty(s))
                return s.Replace('\u2018', '\'').Replace('\u2019', '\'').Replace('\u201c', '\"').Replace('\u201d', '\"');
            else
                return s;
        }
    }
    

    This simply replaces the silly 'smart quotes' with normal quotes.

    [EDIT] Fixed to also support replacement of 'double smart quotes'.

提交回复
热议问题