Streamwriter:波兰语字符被跳过?
我正在尝试制作一个小工具来帮助一些人在 SAP 安装和 Axapta 安装之间转换数据。
我得到一个西欧(Windows)编码(1252)的文本文件。他们添加了一些特殊字符来替换一些波兰字符。现在我的工作是用正确的波兰语字符替换这些特殊字符。
FileStream objFile = new FileStream(FilePath, FileMode.Open, FileAccess.Read,FileShare.Read);
StreamReader objTemp = new StreamReader(objFile, Encoding.GetEncoding(1252));
FileStream objFile2 = new FileStream(FilePath + "_new", FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter objTemp2 = new StreamWriter(objFile2, Encoding.GetEncoding(1252));
while ((strLineText = objTemp.ReadLine()) != null)
{
for (int i = 0; i < strOuterArray.Length; i++)
{
string[] strInnerArray = strOuterArray[i].Split(new char[]{';'});
strLineText = strLineText.Replace(strInnerArray[0], strInnerArray[1]);
}
objTemp2.WriteLine(strLineText);
}
objTemp.Close();
objTemp.Dispose();
objFile.Close();
objFile.Dispose();
objTemp2.Flush();
objTemp2.Close();
如果我调试应用程序并在“objTemp2.WriteLine(strLineText);”上设置断点线。然后我可以看到 strLineText 变量内的值是完美的。特殊字符将替换为正确的波兰语字符。
如果我随后打开书面文件,则找不到正确的波兰语字符。我正在使用“ś”& “Ś”,两者都只是保存为“s”&文件中的“S”。
我是否错过了某些事情或忽略了一些非常重要的事情?
I'm trying to make a small tool to help some guys converting data between a SAP installation and a Axapta installation.
I get a text file i Western European (Windows) encoding (1252). They have put in some special chars to replace some Polish characters. Now it's my job to replace those special chars with the correct Polish characters.
FileStream objFile = new FileStream(FilePath, FileMode.Open, FileAccess.Read,FileShare.Read);
StreamReader objTemp = new StreamReader(objFile, Encoding.GetEncoding(1252));
FileStream objFile2 = new FileStream(FilePath + "_new", FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter objTemp2 = new StreamWriter(objFile2, Encoding.GetEncoding(1252));
while ((strLineText = objTemp.ReadLine()) != null)
{
for (int i = 0; i < strOuterArray.Length; i++)
{
string[] strInnerArray = strOuterArray[i].Split(new char[]{';'});
strLineText = strLineText.Replace(strInnerArray[0], strInnerArray[1]);
}
objTemp2.WriteLine(strLineText);
}
objTemp.Close();
objTemp.Dispose();
objFile.Close();
objFile.Dispose();
objTemp2.Flush();
objTemp2.Close();
If I debug the application and set a breakpoint on the "objTemp2.WriteLine(strLineText);" line. Then I can se that the value inside the strLineText variable is perfect. The special char is replaced by the correct Polish character.
If I open the written file afterwards then I can't find the correct Polish characters. I'm working with "ś" & "Ś", both is just saved as "s" & "S" in the file.
Did I miss something or have I overlooked something very important?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于 windows-1252 代码页中不存在相关的波兰语字符。
您能否确认它们是否在此网格上?
我的建议是使用 UTF-8 编码或类似的编码打开输出流(流编写器),它将支持您需要的所有字符。
I think the problem is that the Polish characters concerned do not exist in the windows-1252 code page.
Can you confirm whether they are on the this grid?
My suggestion would be to open the output stream (stream writer) with a UTF-8 encoding or somesuch, which will support all the characters you need.