Convert Byte Array To String In C# - C# Corner
文章推薦指數: 80 %
Convert C# Byte Array To String. This code snippet is an example of how to convert a byte array into a string. String conversion includes ... ConvertByteArrayToStringInC# MaheshChand UpdateddateSep17,2019 737.1k 0 6 LearntoconvertaC#bytearraytostringinC#and.NETCore.Codeexampleincluded. facebook twitter linkedIn Reddit WhatsApp Email Bookmark Print OtherArtcile Expand ConvertC#ByteArrayToString.Thiscodesnippetisanexampleofhowtoconvertabytearrayintoastring.Stringconversionincludestwotypes.First,conversionanddisplayofC#bytearrayintoastringformat,andsecond,conversionofC#bytesintoactualcharactersofstring. TheBitConverterclassin.NETFrameworkisprovidesfunctionalitytoconvertbasedatatypestoanarrayofbytes,andanarrayofbytestobasedatatypes. TheBitConverterclasshasastaticoverloadedGetBytesmethodthattakesaninteger,doubleorotherbasetypevalueandconvertthattoaarrayofbytes.TheBitConverterclassalsohaveotherstaticmethodstoreversethisconversion.SomeofthesemethodsareToDouble,ToChart,ToBoolean,ToInt16,andToSingle. Thefollowingcodesnippetconvertsabytearrayintoastring. string bitString = BitConverter.ToString(bytes); Thefollowingcodesnippetconvertsabytearrayintoactualcharacterrepresentationofbytesinastring. string utfString = Encoding.UTF8.GetString(bytes, 0, bytes.Length); Listing1isthecompletesourcecode.Thecodeistestedin.NETCore2.2andC#.using System; using System.Text; using System.Security.Cryptography; class Program { static void Main(string[] args) { string plainData = "Mahesh Chand is the founder of C# Corner and an author and speaker."; Console.WriteLine("Raw data: {0}", plainData); // Sha1 Console.WriteLine("============SHA1 Hash============="); // Create SHA1Managed using (SHA1Managed sha1 = new SHA1Managed()) { // ComputeHash - returns byte array byte[] bytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(plainData)); // Merge all bytes into a string of bytes StringBuilder builder = new StringBuilder(); for (int i = 0; i
延伸文章資訊
- 1Byte.ToString 方法(System) - Microsoft Learn
將目前Byte 物件的值,轉換為其相等的字串表示。
- 2Byte Struct in C# - GeeksforGeeks
- 3Convert Byte Array To String In C# - C# Corner
Convert C# Byte Array To String. This code snippet is an example of how to convert a byte array i...
- 4string和byte[]的轉換(C#) - 我的記憶
string和byte[]的轉換(C#). string類型轉成byte[]:. byte[] byteArray = System.Text.Encoding.Default.GetBytes...
- 5Byte to String C# | How to Convert Byte to String In ... - eduCBA
One of the common ways is by using BitConverter.ToString() method. The BitConverter class under S...