Skip to content

Instantly share code, notes, and snippets.

@rarous
Forked from renestein/gist:671054
Created November 10, 2010 16:39
Show Gist options
  • Save rarous/671093 to your computer and use it in GitHub Desktop.
Save rarous/671093 to your computer and use it in GitHub Desktop.
public const string CharUnicodeFormat = "&#{0};";
public static string EncodeUnicodeChars(this string text) {
if (text == null) {
throw new ArgumentNullException("text");
}
return text.Aggregate(
new StringBuilder(),
(sb, ch) => sb.AppendFormat(CharUnicodeFormat, (int)ch),
sb => sb.ToString()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment