0
我之前問過這個問題,並得到了我的答案。 但現在我面臨一個不同的問題。 我有一個文件名。名稱是:<〜'‡™...... 我想解碼它以獲得它的希伯來值。 我使用的代碼:將拉丁字符轉換爲希伯來文編碼
Encoding latinEncoding = Encoding.GetEncoding("Windows-1252");
Encoding hebrewEncoding = Encoding.GetEncoding(862);
byte[] latinBytes = latinEncoding.GetBytes(str);
string hebrewString = hebrewEncoding.GetString(latinBytes);
此代碼的工作不錯,但不是很大。我的意思是幾個字符被解碼爲「?」而不是他們的希伯來文價值。
因此,使用此代碼解碼給定名稱會給我:「כרטס?חשבונו?」而不是「כרטסתחשבונות」。 有這個問題的希伯來字符是:ך,ל,מ,ת。 所有其他解碼都很好。
我找到了一個解決方案,但我想盡量避免它。 解決方案是將給定的字符串保存到文件,然後用862編碼讀取文件。 的代碼是:
string str = "‹˜ˆ‘ ‡™……";
// Get uniqe file name based on current date and time
reportFileName = DateTime.Now.ToString().Replace("/", "-").Replace(":", ";");
// set the file path
string repFilePath = parametersFolder + @"\" + reportFileName;
// save the value to a file with 1255 encoding
File.WriteAllText(repFilePath, str, Encoding.GetEncoding(1255));
// read the value back with 862 encoding
string s = File.ReadAllText(repFilePath, Encoding.GetEncoding(862));
// Delete the file
File.Delete(repFilePath);
// Save the value to a variable.
generatedFileName = s;
與論壇網站不同,我們不使用「謝謝」,或「任何幫助表示讚賞」,或在[so]上簽名。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be - 刪除 - 從帖子)。 – 2014-12-13 18:35:05
@JohnSaunders好的,我會記住下一次。那麼我的問題的答案呢?你有嗎? – subirshan 2014-12-13 18:48:10
你確定這個名字應該是** <〜' ‡™...... **?我收到了正確的結果,並帶有名稱** <〜'‡™......†**此外,由於行中的例外情況,您的解決方法根本無法在我的計算機上運行與子串 – 2014-12-13 19:23:48