cultureinfo

How to print DateTime in Persian format in C#

二次信任 提交于 2019-11-27 01:31:27
问题 What is the simplest way to print c# DateTime in Persian? currently I'm using : static public string PersianDateString(DateTime d) { CultureInfo faIR = new CultureInfo("fa-IR"); faIR.DateTimeFormat.Calendar = new PersianCalendar(); return d.ToString("yyyy/MM/dd", faIR); } Which throws an exception Not a valid calendar for the given culture 回答1: First you must note that you cannot put a Jalali Date in a DateTime object, you will get an exception in dates like "1392/02/31". So you must handle

Async call to the WCF service doesn't preserve CurrentCulture

百般思念 提交于 2019-11-26 23:23:01
问题 According to the answer in this question async/await call should preserve CurrentCulture. In my case, when I call my own async methods, the CurrentCulture is preserved. But if I call some method of WCF service, CurrentCulture isn't preserved, it's being changed to something that looks like server's default thread's culture. I've looked at what managed threads are invoked. It happens so that every line of code was executed on a single managed thread (ManagedThreadId stays the same). And

How to enumerate the LOCALIZED alphabet in C#?

孤街醉人 提交于 2019-11-26 22:04:17
问题 First of all, this is not a duplicate of: Quickest way to enumerate the alphabet Because I need to get all the characters of the alphabet OF AN ARBITRARY (variable) LANGUAGE, and that in the correct ordering sequence. How can I do that without knowing the alphabet of every possible culture/language ? System.Gobalization.Cultureinfo for example has information on date format, and a sorting method, and codepage info. But not info on the alphabet itselfs. Forthermore 'A' to 'Z' ordering

Regular expression to match German number

随声附和 提交于 2019-11-26 21:55:48
问题 I am wondering, how would regular expression for testing correct format of number for German culture would look like. In German, comma is used as decimal mark and dot is used to separate thousands. Therefore: 1.000 equals to 1000 1,000 equals to 1 1.000,89 equals to 1000.89 1.000.123.456,89 equals to 1000123456.89 The real trick, seems to me, is to make sure, that there could be several dots, optionally followed by comma separator 回答1: This is the regex I would use: ^-?\d{1,3}(?:\.\d{3})*(?:,

Replace German characters (umlauts, accents) with english equivalents

扶醉桌前 提交于 2019-11-26 21:48:10
问题 Replace German characters (umlauts, accents) with english equivalents I need to remove any german specific characters from various fields of text for processing into another system which wont accept them as valid. So the characters I am aware of are: ß ä ö ü Ä Ö Ü At the moment I have a bit of a manual way of replacing them: myGermanString.Replace("ä","a").Replace("ö","o").Replace("ü","u")..... But I was hoping there was a simpler / more efficient way of doing it. Since I'll be doing it on

creating custom CultureInfo for country, language combination

爷,独闯天下 提交于 2019-11-26 21:35:00
问题 I am working on a .net 4.5 application that needs to be mult lingual supporting multi cultures etc. The following is sample list of Countries/Languages Russia / Russian Belgium / French Belgium / Dutch For all the above, there is a CultureInfo object that can be created based upon the above culture names ru-RU fr-BE nl-BE When the user enters the site, I set Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture to the culture created with the above names eg. Thread

Get current language in CultureInfo

 ̄綄美尐妖づ 提交于 2019-11-26 20:51:21
问题 How to identify the operating system's language using CultureInfo ? E.g. if the language in Windows is set to French, I need to identify French and load the fr resource files data. 回答1: I think something like this would give you the current CultureInfo: CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; Is that what you're looking for? 回答2: This is what i used: var culture = System.Globalization.CultureInfo.CurrentCulture; and it's working :) 回答3: Current system language is

DateTime and CultureInfo

柔情痞子 提交于 2019-11-26 20:24:45
问题 I have this in my code: var date1 = DateTime.ParseExact(date, "dd.MM.yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); And when my current cultur is dutch ( nl-NL ) instead of May 1st I get January 5th. I think the error is in the second parameter dd.MM.yyyy HH:mm:ss . Is there a way to fix this using the CultureInfo class? 回答1: You may try the following: System.Globalization.CultureInfo cultureinfo = new System.Globalization.CultureInfo("nl-NL"); DateTime dt = DateTime

Format string by CultureInfo

耗尽温柔 提交于 2019-11-26 19:56:58
问题 I want to show pound sign and the format 0.00 i.e £45.00, £4.10 . I am using the following statement: <td style="text-align:center"><%# Convert.ToString(Convert.ToSingle(Eval("tourOurPrice")) / Convert.ToInt32(Eval("noOfTickets")), new System.Globalization.CultureInfo("en-GB")) %></td> But it is not working. What is the problem. Can any one help me??? 回答1: Use the Currency standard format string along with the string.Format method that takes a format provider: string.Format(new System

String sorting issue in C#

断了今生、忘了曾经 提交于 2019-11-26 19:03:57
I have List like this List<string> items = new List<string>(); items.Add("-"); items.Add("."); items.Add("a-"); items.Add("a."); items.Add("a-a"); items.Add("a.a"); items.Sort(); string output = string.Empty; foreach (string s in items) { output += s + Environment.NewLine; } MessageBox.Show(output); The output is coming back as - . a- a. a.a a-a where as I am expecting the results as - . a- a. a-a a.a Any idea why "a-a" is not coming before "a.a" where as "a-" comes before "a." If you want your string sort to be based on the actual byte value as opposed to the rules defined by the current