问题
I am working on a system that needs to read a binary file containing certain Persian names/stock instruments. I need to convert the binary data into string to be used in further processes. I have googled it and haven't really found a solution to my problem. Anyone here who has worked in such a scenario or knows how to tackle such a problem?
Here is the code that I am using to convert the bytes to string (simple as it maybe):
byte[] data = binaryReader.ReadBytes(amountOfData);
string symbolRead = Encoding.ASCII.GetString(data);
FYI, I have tried to change my system locale to Persian and that hasn't helped either. Although it does allow me to view already written text in Persian.
Hoping to find a solution.
Thanks.
回答1:
Don't use ASCII
for encoding. First try using Default
after setting your locale; then try asking directly someone what encoding is most used for Persia, and use this one.
回答2:
Determine what coding is used in your file and use the corresponding encoding instead of Encoding.ASCII.GetString(...)
. Possible values could be Encoding.UTF8.GetString(...)
or Encoding.Default.GetString(...)
to use your system encoding. See documentation of the Encoding class for other possibilities.
来源:https://stackoverflow.com/questions/16651746/converting-binary-data-to-string-in-persian