Advertisement
Revolucent

Unicode To ASCII In C# (Lossy)

Jul 2nd, 2014
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Web;
  4.  
  5. namespace Encodorama
  6. {
  7.     static class StringExtensions
  8.     {
  9.         public static string ToASCII(this string s)
  10.         {
  11.             return Encoding.ASCII.GetString (Encoding.Unicode.GetBytes (s));
  12.         }
  13.     }
  14.  
  15.     class MainClass
  16.     {
  17.         public static void Main (string[] args)
  18.         {
  19.             var s = HttpUtility.HtmlDecode ("† is a Unicode character representing a cross.");
  20.             Console.WriteLine (s);
  21.             Console.WriteLine (s.ToASCII ());
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement