fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. Unicode2HTML("峯");
  8. }
  9.  
  10. private string Unicode2HTML(string unc)
  11. {
  12. StringBuilder sb = new StringBuilder();
  13. //以;將文字拆成陣列
  14. string[] tmp = unc.Split(';');
  15. //檢查最後一個字元是否為【;】,因為有【英文】、【阿拉伯數字】、【&#XXXX;】
  16. //若最後一個要處理的字並非HTML UNICODE則不進行處理
  17. bool Process_last = unc.Substring(unc.Length - 1, 1).Equals(";");
  18. //Debug.WriteLine(tmp.Length + "");
  19. for (int i = 0; i < tmp.Length; i++)
  20. {
  21. //以&#將文字拆成陣列
  22. string[] tmp2 = tmp[i].Split(new string[] { "&#" }, StringSplitOptions.RemoveEmptyEntries);
  23. if (tmp2.Length == 1)
  24. {
  25. //如果長度為1則試圖轉換UNICODE回字符,若失敗則使用原本的字元
  26. if (i != tmp.Length - 1)
  27. {
  28. try
  29. {
  30. sb.Append(Convert.ToChar(Convert.ToInt32(int.Parse(tmp2[0]))).ToString());
  31. }
  32. catch
  33. {
  34. sb.Append(tmp2[0]);
  35. }
  36. }
  37. else
  38. {
  39. sb.Append(tmp2[0]);
  40. }
  41. }
  42. if (tmp2.Length == 2)
  43. {
  44. //若長度為2,則第一項不處理,只處理第二項即可
  45. sb.Append(tmp2[0]);
  46. sb.Append(Convert.ToChar(Convert.ToInt32(int.Parse(tmp2[1]))).ToString());
  47. }
  48. }
  49.  
  50.  
  51. return sb.ToString();
  52. }
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(7,3): error CS0120: An object reference is required to access non-static member `Test.Unicode2HTML(string)'
prog.cs(12,6): error CS0246: The type or namespace name `StringBuilder' could not be found. Are you missing `System.Text' using directive?
prog.cs(30,21): error CS0841: A local variable `sb' cannot be used before it is declared
prog.cs(34,21): error CS0841: A local variable `sb' cannot be used before it is declared
prog.cs(39,16): error CS0841: A local variable `sb' cannot be used before it is declared
prog.cs(45,13): error CS0841: A local variable `sb' cannot be used before it is declared
prog.cs(46,12): error CS0841: A local variable `sb' cannot be used before it is declared
prog.cs(51,10): error CS0841: A local variable `sb' cannot be used before it is declared
Compilation failed: 8 error(s), 0 warnings
stdout
Standard output is empty