ASCII文件 [英] ASCII files
问题描述
我正在尝试加载包含法语
语言中的字符的ASCII文件,其方式与机器的任何Locale无关
配置使用。
所以,如果我有机器,那么默认的Locale是en-US。我打开一些
这样的法语文本:
[C#exaple在任何.net语言中具有相同的行为]
>
StreamReader sr = new StreamReader(" C:\\someFrenchFile.txt");
string strInput = sr.ReadToEnd();
假设文件中包含以下内容:
"LeQuébecenété。"
我在strInput中获得的字符是:
Le Qu?bec en?t ?.
如果我更改控制面板中的默认语言环境并使用
Encoding.Default在StreamReader的构造函数参数中,我在strInput中得到了
的正确字符:
LeQuébecenété。
我想要做的是用正确的
字符加载法语字符串,而不管机器的默认语言环境是什么。什么是以编程方式决定使用所有ASCII字符串的Locale的方式?
Alexandre Leduc
您的流阅读器缺少对第二个参数重要的内容
使用System.Text.Encoding.ASCII
否则它应该eb unicode我相信。
这应该留给你
" Alex Leduc" <乐****** @ netscape.net>在消息中写道
news:eO ************** @ TK2MSFTNGP09.phx.gbl ...我正在尝试加载包含法语
语言字符的ASCII文件,其方式与机器配置使用的Locale无关。
所以如果我有机器的话'默认的区域设置是en-US。我打开一些像这样的法语文本:
[C#exaple在任何.net语言中具有相同的行为]
StreamReader sr = new StreamReader(" ; C:\\someFrenchFile.txt");
string strInput = sr.ReadToEnd();
假设文件中包含以下内容:
LeQuébecenété我在strInput中获得的字符是:
Le Qu?bec en?t ?.
如果我更改控件中的默认语言环境面板和使用
Encoding.Default在StreamReader的构造函数参数中,我在strInput中得到了正确的字符:
LeQuébecenété。
字符加载法语字符串,而不管机器的默认语言环境是什么。什么是以编程方式决定使用所有ASCII字符串的Locale的方法是什么?
Alexandre Leduc
Alex Leduc <乐****** @ netscape.net>在消息中写道
news:eO ************** @ TK2MSFTNGP09.phx.gbl ...我正在尝试加载包含法语
语言字符的ASCII文件,其方式与机器配置使用的Locale无关。
[snip]我想要做的是用正确的
字符加载法语字符串,而不管机器的默认语言环境是什么。什么是以编程方式决定使用所有ASCII字符串的Locale的方法是什么?
如果你知道什么是代码页的文件你可以尝试设置
StreamReader的CurrentEncoding属性到ASCIIEncoding与CodePage
设置为文件的代码页。 [警告!我自己没试过:)]
OTOH如果你想以任意语言读取任意文件我很害怕
它是'不可能......(或者,至少,我不知道的方式......)
Alex Leduc< le ****** @ netscape.net>写道:我正在尝试加载包含法语
语言字符的ASCII文件
假设你的意思是重音人物,这是不可能的。 ASCII没有
包含任何重音字符。
参见 http://www.pobox.com/~skeet/csharp/unicode.html
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet/
如果回复小组,请不要给我发邮件
I''m trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use.
So If I have machine who''s default Locale is "en-US" and I open some
french text like this:
[C# exaple that has the same behaviour in any .net languages]
StreamReader sr = new StreamReader("C:\\someFrenchFile.txt");
string strInput = sr.ReadToEnd();
Suppose the file contains this:
"Le Québec en été."
the characters that I get in strInput are:
"Le Qu?bec en ?t?."
If I change the default Locale in the Control Panel and use
Encoding.Default in the StreamReader''s constructor parameters, I get the
right characters in strInput:
"Le Québec en été."
What I''d like to be able to do is load the french string with the right
characters regardless of what''s the machine''s default Locale. What''s the
way to programmatically decide what Locale to use with all ASCII strings?
Alexandre Leduc
Your stream reader is missing something important for the second parameter
use System.Text.Encoding.ASCII
otherwise it should eb unicode i believe.
This should helo you
"Alex Leduc" <le******@netscape.net> wrote in message
news:eO**************@TK2MSFTNGP09.phx.gbl...I''m trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use.
So If I have machine who''s default Locale is "en-US" and I open some
french text like this:
[C# exaple that has the same behaviour in any .net languages]
StreamReader sr = new StreamReader("C:\\someFrenchFile.txt");
string strInput = sr.ReadToEnd();
Suppose the file contains this:
"Le Québec en été."
the characters that I get in strInput are:
"Le Qu?bec en ?t?."
If I change the default Locale in the Control Panel and use
Encoding.Default in the StreamReader''s constructor parameters, I get the
right characters in strInput:
"Le Québec en été."
What I''d like to be able to do is load the french string with the right
characters regardless of what''s the machine''s default Locale. What''s the
way to programmatically decide what Locale to use with all ASCII strings?
Alexandre Leduc
"Alex Leduc" <le******@netscape.net> wrote in message
news:eO**************@TK2MSFTNGP09.phx.gbl...I''m trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use. [snip] What I''d like to be able to do is load the french string with the right
characters regardless of what''s the machine''s default Locale. What''s the
way to programmatically decide what Locale to use with all ASCII strings?
If you know what''s the code page of the file you can try to set
StreamReader''s CurrentEncoding property to ASCIIEncoding with the CodePage
set to file''s code page. [Warning! haven''t tried it myself :)]
OTOH if you want to read arbitrary file in arbitrary language I''m afraid
it''s not possible... (or, at least, I don''t know the way...)
Alex Leduc <le******@netscape.net> wrote:I''m trying to load ASCII files that contain characters from the French
language
Assuming you mean accented characters, that''s impossible. ASCII doesn''t
contain any accented characters.
See http://www.pobox.com/~skeet/csharp/unicode.html
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
这篇关于ASCII文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!