Converting string of ASCII code list to byte array

408 Views Asked by At

Hello my database has some string like "24629702857295607830195970123951263875654....". This string is produced as below:

fs = new FileStream(samplePicture.Text, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
bytes = br.ReadBytes((int)fs.Length);

Something like that is only converting the numbers to its ASCII character and it is not what I want:

byte[] bytes = Encoding.ASCII.GetBytes(byteString);

If it was a hex string it can be converted by having substrings with 2 length parts. But I couldn't convert this type of string. If you don't want to write the code it works also just an idea how to separate ASCII characters like : 246, 29, 70, 28, 57,...

Summary Edit: Actually I am trying to reverse the string back to its byte array. String is generated like here:

    fs = new FileStream(samplePicture.Text, FileMode.Open, FileAccess.Read);
    br = new BinaryReader(fs);
    bytes = br.ReadBytes((int)fs.Length);
    
    for(int i = 0; i < bytes.Length; i++)
    myStringBuilder.Append(bytes[i]);

I can't reach the file or anything else. All I have is this string.

0

There are 0 best solutions below