ASP.NET - 什么字符,则Server.HtmlEn code恩code到命名字符条目 [英] ASP.NET - What Characters does Server.HtmlEncode Encode into Named Character Entities

查看:131
本文介绍了ASP.NET - 什么字符,则Server.HtmlEn code恩code到命名字符条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么字符,则Server.HtmlEn code EN code到命名字符实体?

What characters does Server.HtmlEncode encode into named character entities?

到目前为止,我只找到<$​​ C $ C>&放大器; LT; &放大器; GT; &放大器;放大器;和与放大器; QUOT; 想必一定有比这更

So far I have only found &lt; &gt; &amp; and &quot; surely there must be more than this?

推荐答案

这是 HtmlEn code 的code,所以在这里你可以看到如何他们做到了。

This is the code of HtmlEncode, so here you can see how they done it.

public static unsafe void HtmlEncode(string value, TextWriter output)
{
    if (value != null)
    {
        if (output == null)
        {
            throw new ArgumentNullException("output");
        }
        int num = IndexOfHtmlEncodingChars(value, 0);
        if (num == -1)
        {
            output.Write(value);
        }
        else
        {
            int num2 = value.Length - num;
            fixed (char* str = ((char*) value))
            {
                char* chPtr = str;
                char* chPtr2 = chPtr;
                while (num-- > 0)
                {
                    chPtr2++;
                    output.Write(chPtr2[0]);
                }
                while (num2-- > 0)
                {
                    chPtr2++;
                    char ch = chPtr2[0];
                    if (ch <= '>')
                    {
                        switch (ch)
                        {
                            case '&':
                            {
                                output.Write("&amp;");
                                continue;
                            }
                            case '\'':
                            {
                                output.Write("&#39;");
                                continue;
                            }
                            case '"':
                            {
                                output.Write("&quot;");
                                continue;
                            }
                            case '<':
                            {
                                output.Write("&lt;");
                                continue;
                            }
                            case '>':
                            {
                                output.Write("&gt;");
                                continue;
                            }
                        }
                        output.Write(ch);
                        continue;
                    }
                    if ((ch >= '\x00a0') && (ch < 'Ā'))
                    {
                        output.Write("&#");
                        output.Write(ch.ToString(NumberFormatInfo.InvariantInfo));
                        output.Write(';');
                    }
                    else
                    {
                        output.Write(ch);
                    }
                }
            }
        }
    }
}

这篇关于ASP.NET - 什么字符,则Server.HtmlEn code恩code到命名字符条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆