我有一个包含波斯语单词并使用 ANSI 编码保存的文本文件。当我尝试从文本文件中读取波斯语单词时,我得到了一些字符,例如“?”。为了解决这个问题,我将文件编码更改为 UTF8 并重新编写了文本文件。以下是更改文件编码的方法:
public void Convert2UTF8(string filePath)
{
//first, read the text file with "ANSI" endocing
StreamReader fileStream = new StreamReader(filePath, Encoding.Default);
string fileContent = fileStream.ReadToEnd();
fileStream.Close();
//Now change the file encoding and replace it with the UTF8
StreamWriter utf8Writer = new StreamWriter(filePath.Replace(".txt", ".txt"), false, Encoding.UTF8);
utf8Writer.Write(fileContent);
utf8Writer.Close();
}
现在第一个问题解决了;但是,这里还有另一个问题:每次我想从 SQL Server 数据库表中搜索一个波斯语单词时,结果为空,而该记录确实存在于数据库表中。
找到表中存在的波斯语单词的解决方案是什么?我目前使用的代码如下:
SELECT * FROM [dbo].[WordDirectory]
WHERE Word = N'کلمه'
Word
是保存波斯语单词的字段。字段的类型是NVARCHAR
。我的 SQL Server 版本是 2012。我应该更改排序规则吗?