Skip to content

Instantly share code, notes, and snippets.

@rexcfnghk
Last active July 11, 2016 15:57
Show Gist options
  • Save rexcfnghk/566e3604b08e3250211b to your computer and use it in GitHub Desktop.
Save rexcfnghk/566e3604b08e3250211b to your computer and use it in GitHub Desktop.
Convert a string to bytes
public static class StringEncodingUtilities
{
public static IEnumerable<string> GetBytes(this string input, Encoding encoding)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
}
return from b in encoding.GetBytes(input)
select $"U+00{b:X2}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment