Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.
Posted
Updated 20-Dec-11 11:04am
v3

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.
 
Share this answer
 
Comments
Member 8256632 20-Dec-11 15:09pm    
Thank you very much. That's why I cannot find useful information. Thank you for your direction.
Sergey Alexandrovich Kryukov 20-Dec-11 19:15pm    
Correct, but this also needs information on use of Unicode BOM -- very important.
Please see my answer.
--SA
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
 
Share this answer
 
Comments
Wendelius 21-Dec-11 0:29am    
Good clarification, 5
Sergey Alexandrovich Kryukov 21-Dec-11 1:05am    
Overall, these things are poorly understood by many, as well as Unicode in general. So many people thing this is a 16-bit code, which is not even close to the truth...
--SA
Member 8256632 21-Dec-11 9:47am    
Thank you SA. but in my text file, there are just numbers. in canada, we use 1,000.00, but in german, they use 1.000,00. totally different. Now I use System.IO.StreamReader oStream = new System.IO.StreamReader(this.m_sFileName);
to read that file, but I cannot even read the numbers in. How can I read that file? I mean for now, we put the encoding aside.
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.
 
Share this answer
 
 
Share this answer
 
Comments
Member 8256632 21-Dec-11 9:49am    
Thank you Amir. It is good to know these information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900