我有一个用代码页 850 编码的文本文件。我正在按以下方式读取此文件:
using (var reader = new StreamReader(filePath, Encoding.GetEncoding(850)))
{
string line;
while ((line = reader.ReadLine()) != null)
{
//...
}
//...
}
现在我需要在代码页 850 中该字符的从零开始的索引上方的循环中字符串 line
中的每个字符,例如:
for (int i = 0; i < line.Length; i++)
{
int indexInCodepage850 = GetIndexInCodepage850(line[i]); // ?
//...
}
这可能吗?int GetIndexInCodepage850(char c)
看起来像什么?
最佳答案
使用Encoding.GetBytes()在线上。 CP850 是一种 8 位编码,因此字节数组的元素数量应该与字符串的字符数量一样多,每个元素都是字符的值。
关于c# - 如何确定 C# 中字符的代码页 850 中的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7256337/