Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of .net Encoding.UTF8.GetString

Tags:

c#

encoding

What is the complementary method of Encoding.UTF8.GetString

That is, if Encoding.UTF8.GetString decodes bytes in a byte array into a string, what method encodes a string into bytes in a byte array, so that

var somestring == Encoding.UTF8.GetString(method(someString));

is true?

like image 361
user1443098 Avatar asked Mar 17 '26 08:03

user1443098


1 Answers

The reverse method is Encoding.UTF8.GetBytes. Similar classes exist with the same method for ASCII and UTF16 encodings.

System.Text.Encoding.UTF8.GetBytes("TestString")
like image 123
BradleyDotNET Avatar answered Mar 18 '26 20:03

BradleyDotNET



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!