![]() Just what I needed to know about to and from Base64String conversions.Īlex is correct about UTF-8. The small method below combines the two methods I’ve described to create a Base64 encoded string from a normal string. I imagine most of you are working with ASCII encoding, so here we’ll call on the ASCIIEncoding.ASCIII class, and use it’s GetBytes to convert a string to bytes. You’d think the string class would have a nice static method to handle this, but alas it does not. For us, this means we have to take our string and convert it to a byte array. It does make a certain amount of sense, typically you aren’t encoding a simple string but instead a binary object such as a file, which is usually represented as an array of bytes. ![]() On the ToBase64String, we have a bit of a challenge, since it expects a byte array and not a string to be passed in. ![]() It turns out the System.Convert has two handy methods for dealing with Base64, ToBase64String and FromBase64String. Net, once you figured out which class libraries you needed to combine. It turned out to be relatively simple in. I recently had the need to convert simple strings back and forth from Base64 encoding. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |