表情符号/表情符号的webbrowser

时间:2016-01-22 16:12:39

标签: c# encoding character-encoding webbrowser-control

民间,

我正在使用表情符号/表情符号在网页上发帖。但发布后该网站不显示表情符号。你必须使用不同的编码吗?如果是这样我该怎么办? 示例有这个表情符号⛪该网站只显示我that出现其他特殊字符。

if (currentElement.GetAttribute("type") == "submit")
    if (currentElement.Name == "view_post") 
    {
       string postagem = txtPublicacao.Text;

        HtmlElement elea = webBrowser1.Document.GetElementById("u_0_0");
        if (elea != null)
            elea.SetAttribute("value", postagem);

        currentElement.InvokeMember("click");

    }

1 个答案:

答案 0 :(得分:0)

我认为你可以通过确保将这些块括在括号中来阻止自己经历未来的悲痛:

if (currentElement.GetAttribute("type") == "submit")
{
    if (currentElement.Name == "view_post") 
    {
       string postagem = txtPublicacao.Text;

        HtmlElement elea = webBrowser1.Document.GetElementById("u_0_0");
        // if condition and response either on one line:
        if (elea != null) elea.SetAttribute("value", postagem);
        // ...or use "{}" in preparation for possible future additions to the reponse to the if condition
        if (elea != null) 
        {
            elea.SetAttribute("value", postagem);
        }
        currentElement.InvokeMember("click");    
    }
}

或者更好的是,因为在执行代码之前你有两个连续的“ifs”,所以将它们组合起来:

if ((currentElement.GetAttribute("type") == "submit") && 
    (currentElement.Name == "view_post"))
{
    string postagem = txtPublicacao.Text;    
    HtmlElement elea = webBrowser1.Document.GetElementById("u_0_0");
    if (elea != null) elea.SetAttribute("value", postagem);
    currentElement.InvokeMember("click");    
}