£ 如何转成"£"这样,如果用c#程序来转应该怎么写这段代码?请高手赐教!谢谢!

解决方案 »

  1.   

    用Replace函数替代应该就可以了吧
      

  2.   

    htmlencode(yourchar ,encoding )
      

  3.   

    方法一:string str = "1£2";str = System.Web.HttpUtility.HtmlEncode(str);Console.WriteLine(str);str = System.Web.HttpUtility.HtmlDecode(str);Console.WriteLine(str);Console.Read();方法二:string str = "1£2";str = str.Replace("£", "£");Console.WriteLine(str);str = str.Replace("£", "£");Console.WriteLine(str);Console.Read();
      

  4.   

    ^o^ 若使用方法一, 则需引用 System.Web.dll ...
      

  5.   

    System.Web.HttpUtility.HtmlEncode(yourstring);
      

  6.   

    System.Web.HttpUtility.HtmlEncode(yourstring);
    这样不行,还有没有其它办法?
      

  7.   

    实测了一下,System.Web.HttpUtility.HtmlEncode()只能编码<>之类的符号:"1<£>2"  ->  "1&lt;£&gt;2"关注,期待更好的方法。
      

  8.   

    using System;
    using System.Text;
    using System.Collections.Generic;class Test
    {
      static Dictionary<char, string> htmlChar;
      
      static Dictionary<char, string> HtmlCharInit()
      {
        htmlChar = new Dictionary<char, string>();
        htmlChar['£'] = "pound";
        htmlChar['‰'] = "permil";
        // 还有更多符号 ...
        return htmlChar;
      }
      
      static string MyHtmlEncode(string s)
      {
        StringBuilder sb = new StringBuilder();
        foreach (char c in s)
        {
          string t;
          if (htmlChar.TryGetValue(c, out t)) sb.AppendFormat("&{0};", t);
          else sb.Append(c);
        }
        return sb.ToString();
      }  static void Main()
      {
        HtmlCharInit();
        string str = "1<£‰¤>2";
        Console.WriteLine(str);
        str = System.Web.HttpUtility.HtmlEncode(str);
        str = MyHtmlEncode(str);
        Console.WriteLine(str);
      }
    }
    /*
    程序输出:
    1<£‰¤>2
    1&lt;&pound;&permil;&#164;&gt;2
    */
      

  9.   

    从上面的程序看,System.Web.HttpUtility.HtmlEncode()可以转换'¤'为"&#164;"。先用System.Web.HttpUtility.HtmlEncode()转换一下,只要System.Web.HttpUtility.HtmlEncode()能转换的,就不必加到htmlChar字典中了。
      

  10.   

    htmlChar['£']   =   "pound"; 
            htmlChar['‰']   =   "permil"; 
    楼上的这样行不通啊,问题是其它一些字符转换后(即等号右边的那部分)是不知道的,