ellapt

T14.10.ConvertToUTF

Feb 3rd, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class ConvertToUTF
  5. {
  6. static void Main()
  7. {
  8. Console.WriteLine("Convert a string to a sequence of C# Unicode character literals");
  9. Console.WriteLine("Enter a string (Enter will assume 'Hi!') : ");
  10. string inputStr = Console.ReadLine();
  11. if (inputStr == "")
  12. {
  13. inputStr = "Hi!";
  14. }
  15.  
  16. StringBuilder utfString = new StringBuilder(inputStr.Length * 6);
  17.  
  18. foreach (char c in inputStr)
  19. {
  20. int code=(int)c;
  21. utfString.AppendFormat("\\u{0:X4}",code);
  22. }
  23. Console.WriteLine("The Unicode of the string {0} is: {1}", inputStr,utfString.ToString());
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment