How to convert string to ascii value in C#?

QuestionsCategory: C#How to convert string to ascii value in C#?
Himanshu SHimanshu S asked 1 year ago

How to convert string value to ASCII value in C#?

1 Answers
Mahesh DeshmaneMahesh Deshmane answered 1 year ago

below are two solution for converting string to ascii value using C#
Solution 1:

Start your code here
string value = "THIS IS THE GOOD KEY"; // Convert the string into a byte[]. byte[] asciiBytes = Encoding.ASCII.GetBytes(value);

Solution 2:

string str = "THIS IS THE GOOD KEY";
byte[] asciiByte = new byte[str.Length];
for(int i = 0;i< str.Length;i++)
{
     asciiByte[i] = (byte) str[i];
}