×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C#
Posted by: Tobias Richter
Added: Jan 14, 2015 10:19 AM
Modified: Jan 14, 2015 10:20 AM
Views: 17
Tags: c# encoding
  1. public static string AsUtf8(this string str)
  2. {
  3.     var bytes = new byte[str.Length];
  4.     for (int i = 0; i < str.Length; ++i)
  5.     {
  6.         bytes[i] = (byte)str[i];
  7.     }
  8.  
  9.     string utf8Str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
  10.     return utf8Str;
  11. }