C#特殊字符转义

    ///
    /// 对转义字符进行处理
    /// 左尖括号: < <
    /// 右尖括号: > >
    /// 单引号  : ' '
    /// 双引号  : " " 
    /// (shift+7):& & 
    ///

    public class TransferredMeaning
    {
        static public string Transferred(string Meaning)
        {
            //普通字符变换成转义字符
            Meaning = Meaning.Replace("&", "&");
            Meaning = Meaning.Replace("<", "<");
            Meaning = Meaning.Replace(">", ">");
            Meaning = Meaning.Replace("'", "'");
            Meaning = Meaning.Replace("\"", """);
            return Meaning;
        }


        static public string UnTransferred(string Meaning)
        {
            //转义字符变换成普通字符
            Meaning = Meaning.Replace("<", "<");
            Meaning = Meaning.Replace(">", ">");
            Meaning = Meaning.Replace("'", "'");
            Meaning = Meaning.Replace(""","\"");
            Meaning = Meaning.Replace("&","&");


            return Meaning;
        }

你可能感兴趣的:(C#特殊字符转义)