问题
I have a C# file that has some arabic text in it, I got the file from another source, the arabic text is now scrambled. looking like this ("ÇáãæÇÞÚ ÇáÞÇÈáÉ ááÊØæíÑ ÇáÓíÇÍì"), I tried to save the file in another encoding (UTF-8) but still same result, I desperately need to read this arabic text as this is the only back up we have
Thanks
回答1:
Try right-clicking the file in VS solution explorer, then choose:
Open With... -> CSharp Editor with Encoding
This should force VS to read the file with a unicode encoding, rather than as single byte text.
Although you are saving in UTF-8
, the file may be missing the Byte Order Mark (BOM)
for UTF-8
at the beginning of the file. A BOM
for UTF-8
files is optional.
Update
If the file has no BOM
, try:
... CSharp Editor with Encoding -> Unicode (UTF-8 without signature) codepage 65001
Update
The file is not unicode encoded, it requires opening with an Arabic codepage. Try opening as follows, or with one of the other Arabic codepages:
... CSharp Editor with Encoding -> Arabic (864) - Codepage 864
回答2:
use the following code if you want to load or save to file using rtb text without streams:
saveFile.ShowDialog();
rtbText.SaveFile(saveFile.FileName,RichTextBoxStreamType.PlainText);
openFile.ShowDialog();
rtbText.LoadFile(openFile.FileName,RichTextBoxStreamType.PlainText);
来源:https://stackoverflow.com/questions/6828148/how-to-open-arabic-text-file-with-correct-encoding-in-visual-studio