Last active
July 11, 2016 15:57
-
-
Save rexcfnghk/566e3604b08e3250211b to your computer and use it in GitHub Desktop.
Convert a string to bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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