Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the Encoding from a BASE64STRING
    text
    copied!<p>Below is the code with a description of my problem:</p> <ol> <li><p>I need to find the encoding of this file, but not now!</p> <pre><code>string FilePath = @"C:\01 New.txt"; System.IO.FileStream inFile = new System.IO.FileStream(FilePath, System.IO.FileMode.Open,System.IO.FileAccess.Read); byte[] binaryData = new Byte[inFile.Length]; long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length); inFile.Close(); string base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);// Converting ToBase64String Console.WriteLine("base64String is " + base64String); </code></pre> <p>Please assume that the above process is done by something else, and it only returns "base64String". Now I need to read it properly.</p></li> <li><p>For that, I need the "ENCODING" of the base64String:</p> <pre><code>byte[] s = Convert.FromBase64String(base64String); switch (GET_ENCODING(base64String)) { case "ASCII": Console.WriteLine("ASCII text is " + Encoding.ASCII.GetString(s).Trim()); break; case "Default": Console.WriteLine("Default text is " + Encoding.Default.GetString(s).Trim()); break; case "UTF7": Console.WriteLine("UTF7 text is " + Encoding.UTF7.GetString(s).Trim()); break; case "UTF8": Console.WriteLine("UTF8 text is " + Encoding.UTF8.GetString(s).Trim()); break; case "BigEndianUnicode": Console.WriteLine("BigEndianUnicode " + Encoding.BigEndianUnicode.GetString(s).Trim()); break; case "UTF32": Console.WriteLine("UTF32 text is " + Encoding.UTF32.GetString(s).Trim()); break; default: break; } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload