检测文本文件的语言环境? [英] detect the locale of a text file?

查看:86
本文介绍了检测文本文件的语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有没有一种方法可以检测.txt文件的语言环境?我的应用程序需要从本地用户读取一个文本文件.我需要知道希腊文还是法文的文件?或者,我只是读入该文件.我正在使用Visual Studio2008.我最初的想法是读入文件并将每个字符串转换为中性字符串.很抱歉这个愚蠢的问题.我在网上找不到很多信息.非常感谢.

Hi all,

Is there a way to detect a .txt file''s locale? My application needs read a text file from local user. Do I need know the file from greek or french? Or I just read that file in. I am using visual studio 2008. my original thought is to read file in and convert each string to neutral string. Sorry for the stupid question. I cannot find much information online. Thanks a lot.

推荐答案

文本文件没有语言环境信息.文件之间的不同之处在于数据的编码.例如,可以使用ANSI或Unicode等保存一个简单的文本文件.
Text files don''t have locale information. What may differ between files is the encoding of the data. For example a simple text file can be saved using ANSI or Unicode etc.


整个语言环境已过时.语言环境的概念仍在Windows的不同版本中使用,大多以简陋的形式出现.如今,使用Unicode.

现在,文本文件可以具有UTF字节顺序标记(BOM),用于将使用 UTF 的信息告知文本编辑器.对于.NET API,文本流和阅读器类具有通过BOM自动识别Unicode UTF的选项.启用Unicode的文本编辑器具有另存为"选项,该选项允许选择UTF或不选择UTF,这意味着所有良好的ANSI.

有关更多详细信息,请参见:
http://unicode.org/ [ ^ ],
http://unicode.org/faq/utf_bom.html [
The whole idea of locale is obsolete. A notion of locale is still used in different version of Windows, mostly in the form of rudiment. These days, Unicode is used.

Now, the text files can have a UTF Byte-Order Marker (BOM) used to inform a text editor on what UTF is used. As to .NET API, text stream and reader classes have options to auto-recognize Unicode UTFs by the BOM. Unicode-enabled text editors have the "Save as" option which allows to select the UTF or none, which means all good ANSI.

For further detail, see:
http://unicode.org/[^],
http://unicode.org/faq/utf_bom.html[^].

—SA


现在我的文本文件来自希腊语,当我读取该文件时,出现问题说格式无效,无法读取".我至少应该如何读取此文件,然后我可以做
value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
进行转换.
Now my text file from greek, when I read this file in, it has problem said "has invalid formatting and can not be read". How can I read this file in at least, then I can do
value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
to convert it.


这篇关于检测文本文件的语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆