Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am so frustrated about this topic. I have a text file from Greek, it only includes numbers. My application is c# application and default locale is english. Now I want to read this greek text file into my application. I cannot get correct numbers because of the two number formats are different. Could anybody tell me how to convert greek number format to english, then I can use my application?

any comment is highly appreciated!
Posted
Comments
Sergey Alexandrovich Kryukov 22-Dec-11 10:51am    
What is the format of the file? What do you mean by different format of a number? Decimal point?
--SA
Member 8256632 22-Dec-11 11:08am    
Yes. In greek, they write like 1.000,00. In english, we use 1,000.00. This is the different.
Sergey Alexandrovich Kryukov 22-Dec-11 11:40am    
Right, there also can be a thousands separator. The solution I explained below should cover everything.
--SA

I hope you understand that the numeric data itself has no cultural difference, but the representation if the numbers in the form of text may have. One such difference is a decimal point, for example. If this the problem?

In this case, you only need to read data in some specific culture.

You can change the culture of a current thread before your text reader reads and parses the data:
C#
System.Globalization.CultureInfo savedCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
try {
   //the culture of Greek (Greece):
   System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("el-GR");
   System.Threading.Thread.CurrentThread.CurrentCulture = culture;
   //read and parse data in a usual way
} finally {
   System.Threading.Thread.CurrentThread.CurrentCulture = savedCulture;
}


Essentially, all that makes a difference while parsing a text into a numeric data; so, on a detail level, you can do

C#
// use the culture defined above as System.IFormatProvider
// as System.Globalization.CultureInfo implements System.IFormatProvider
double value = double.Parse(someText, culture); //will throw exception in the case of invalid format
// or
if (!double.TryParse(someText, out value)) { /* ... */ } //without throwing exception
// here, we assume someText representing a single number 
—SA
 
Share this answer
 
v4
Comments
Member 8256632 22-Dec-11 11:28am    
You are such a genius. I cannot believe you know so many things about c# stuff. Admire you. Merry Christmas guys.
Sergey Alexandrovich Kryukov 22-Dec-11 11:33am    
Thank you for these words but this is an extreme exaggeration. I just learned to read :-)

Good luck, call again; Merry Christmas to you!
--SA
Abhinav S 22-Dec-11 11:34am    
My 5!
Sergey Alexandrovich Kryukov 22-Dec-11 11:36am    
Thank you, Abhinav.
--SA
Monjurul Habib 22-Dec-11 12:06pm    
5!
Since you have only 10 digits, I would think you read the file digit by digit and parse each digit into its equivalent English translation.
 
Share this answer
 
v2
Comments
Wendelius 22-Dec-11 12:15pm    
Don't understand the vote of 1, compensated.
Abhinav S 22-Dec-11 13:27pm    
Thanks Mika.
You have to start from the back-end of the string.
 
Share this answer
 
Comments
Member 8256632 22-Dec-11 11:07am    
Could you give me more detailed instruction? I am newbie to c#.
#realJSOP 22-Dec-11 11:20am    
I was just bein' a smart-ass.

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