Tag: cultureinfo

如何使用文化将变量中的波斯数字转换为英文数字?

我想更改保存在变量中的波斯数字,如下所示: string Value=”۱۰۳۶۷۵۱”; 至 string Value=”1036751″; 我怎样才能使用像文化信息这样简单的方法来做到这一点? 我的示例代码是: List NERKHCOlist = new List(); NERKHCOlist = ScrappingFunction(NERKHCO, NERKHCOlist); int NERKHCO_Price = int.Parse(NERKHCOlist[0]);//NERKHCOlist[0]=۱۰۳۶۷۵۱ <=所以它不能解析为int 这是在我的函数中,它返回列表项中包含波斯数字的列表 protected List ScrappingFunction(string SiteAddress, List NodesList) { string Price = “null”; List Targets = new List(); foreach (var path in NodesList) { HtmlNode node = document.DocumentNode.SelectSingleNode(path.ToString());//recognizing Target Node Price = node.InnerHtml;//put text […]

本地化资源不会更改页面中的某些超链接控件

以上是开发中网站的截图… 我们有一个DropdownList控件,并在其SelectedIndexChanged上回发它,然后我们更改站点文化,然后加载相应的资源文件。 DropDownList ASP.NET代码 所有网页inheritance的公共类 using System; using System.Web; using System.Threading; using System.Globalization; public class languagebase : System.Web.UI.Page { protected override void InitializeCulture() { try { string LanguageCode = Request[“ctl00$ucMenu$ddlLanguage”]; // Language Drop Down Control in Front End if (!LanguageCode.IsNullOrEmpty()) { setCulture(LanguageCode); // Set Culture language from drop down Request.Cookies[“LanguageCode”].Value = LanguageCode; // Update REQUEST […]

修改应用程序范围,显示DateTime

对于我们开发的应用程序,我们在应用程序的任何地方都使用”G”格式。 我们想要改变这种格式: 我们需要在第二个数字后显示第一个数字。 例如: 29.07.2014 08:54:36.1 我们希望能够在CurrentCulture进行更改。 这是我们在当前文化中唯一想要改变的东西,所以如果以前,我们有以下格式: 2014/07/29 08:54:36 AM 然后我们想拥有 2014/07/29 08:54:36.1 AM 如果在我之前 29.07.2014 08:54:36 然后我们想拥有 29.07.2014 08:54:36.1 很高兴,如果我们收到的DateTime ,没有要显示的数字(= 0十分之一秒),则不显示。

C#连接到Oracle DB DateTime格式

我有一个连接到Oracle后端的.Net webapp。 我有一个基页,每个页面使用我设置的地方 protected override void OnPreInit(EventArgs e) { System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(“en-CA”); // Creating the DateTime Information specific to our application. System.Globalization.DateTimeFormatInfo dateTimeInfo = new System.Globalization.DateTimeFormatInfo(); // Defining various date and time formats. dateTimeInfo.DateSeparator = “/”; dateTimeInfo.LongDatePattern = “dd-MMM-yyyy”; dateTimeInfo.ShortDatePattern = “dd-MMM-yyyy”; dateTimeInfo.MonthDayPattern = “dd/MM”; dateTimeInfo.LongTimePattern = “HH:mm”; dateTimeInfo.ShortTimePattern = “HH:mm”; dateTimeInfo.FullDateTimePattern = […]

字符串未被识别为有效的DateTime?

我尝试将字符串转换为datetime时间,但每次我得到: 字符串未被识别为有效的DateTime。 代码是: string format = “dd/MM/yyyy”; obj.TransDate = DateTime.ParseExact(lbl_TransDate.Text.Split(‘/’)[0] + “/” + lbl_TransDate.Text.Split(‘/’)[1] + “/” + lbl_TransDate.Text.Split(‘/’)[2], format, CultureInfo.InvariantCulture); 当我调试我尝试解析它的日期是: 12/4/2012

如何将阿拉伯语Umm Al-Qura日期字符串解析为.NET DateTime对象?

我在Umm Al-Qura日历中有以下阿拉伯语日期,我要解析为.NET DateTime对象: الأربعاء,17ذوالحجة,1436 该日期相当于格里高利历中的2015年9月30日。 我一直在尝试使用以下“标准”C#代码来解析这个日期,但没有成功: var cultureInfo = new CultureInfo(“ar-SA”); cultureInfo.DateTimeFormat.Calendar = new UmAlQuraCalendar(); // the default one anyway var dateFormat = “dddd، dd MMMM، yyyy”; //note the ، instead of , var dateString = “‏الأربعاء‏، 17‏ ذو الحجة‏، 1436”; DateTime date; DateTime.TryParseExact(dateString, dateFormat, cultureInfo.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces, out date); 无论我做什么, TryParseExact的结果总是false 。 如何在.NET中正确解析此字符串? 顺便说一句,如果我从DateTime对象开始,我可以使用ToString()在DateTime上的重载创建上面的确切日期字符串而不会出现问题。 我显然不能以相反的方式做到这一点。

为什么我会得到“文化不受支持”以及如果有什么,我该怎么做呢?

我在这里的“返回”行有一个断点: [HttpGet] [Route(“api/Test/{id1}/{id2}”)] public NRBQEntity GetTestMessage(String id1, String id2) { return NRBQClient.GetTestMessage(id1, id2); } 虽然它没有崩溃应用程序,当我达到这一点,我得到, “ Exception:Thrown:”不支持文化。“(System.Globalization.CultureNotFoundException)抛出了System.Globalization.CultureNotFoundException:”不支持文化。 “ 试图支持哪种文化,为什么不支持这种文化,以及我应该做些什么来支持这种文化? UPDATE 回答斯潘利: 除了代表“BarbeQue的新骑士”之外,它还是一个“骨架”(现在)实体,看起来像这样: public class NRBQEntity { public NRBQEntity() { } public String Value { get; set; } } 更新2 对AnotherUser的回答: 这不是我的代码,所以我只是在试图理解它; 它作为一个起点提供给我复制/重构现有的独立项目,并将其纳入“解决方案”。 已经说过,回答你的问题,这里是解决方案中“GetTestMessage()”的所有实例: [HttpGet] [Route(“api/Test/{id1}/{id2}”)] public NRBQEntity GetTestMessage(String id1, String id2) { return NRBQClient.GetTestMessage(id1, id2); […]

如何在CultureInfo中显示尼日利亚奈拉符号(c#)

我想用尼日利亚货币符号显示金额(即N通过“ ₦ ”双击)。 我已经尝试过ff段代码,它只显示N的数量,而不是正确的符号(N通过double双击) @{ IFormatProvider currencyFormat = new System.Globalization.CultureInfo(“HA-LATN-NG”); } Amount: @string.Format(currencyFormat, “{0:c}”, Model.Amount) 任何想法如何实现呢?

如何以文化感知的方式格式化TimeSpan的HH:mm:ss分隔符?

我正在开发一个可以在世界上许多国家看到的应用程序。 没有多少国家/地区显示小时,分钟和秒钟以外的其他内容:作为分隔符,但有一些,我想确保时区格式正确的区域。 DateTime很棒,但TimeSpan不是。 这些片段来自我在Visual Studio 2010中的即时窗口,使用.Net 4,我的区域设置为Malayalam(印度)。 dateTime.Now调用还反映了我的时钟,Microsoft Outlook和其他领域的时间显示方式。 DateTime.Now.ToString() “02-10-12 17.00.58” http://msdn.microsoft.com/en-us/library/dd784379.aspx表示“如果formatProvider为null,则使用与当前区域性关联的DateTimeFormatInfo对象。如果format是自定义格式字符串,则为formatProvider参数被忽略了。“ 按理说那我甚至不需要传递当前的CultureInfo。 我想要的格式是hh.mm.ss但是显而易见hh:mm:ss在大多数其他语言中,如果还有其他可能性,它应该自动反映这些 – 基本上TimeSpan 应该是文化意识,就像DateTime一样是。 然而: timeRemaining.ToString() “00:02:09” timeRemaining.ToString(“c”) “00:02:09” timeRemaining.ToString(“c”, CultureInfo.CurrentCulture) “00:02:09” timeRemaining.ToString(“g”) “0:02:09” timeRemaining.ToString(“G”) “0:00:02:09.0000000” timeRemaining.ToString(“t”) “00:02:09” timeRemaining.ToString(“g”, CultureInfo.CurrentCulture) “0:02:09” timeRemaining.ToString(“g”, CultureInfo.CurrentUICulture) “0:02:09” timeRemaining.ToString(“G”, CultureInfo.CurrentUICulture) “0:00:02:09.0000000” timeRemaining.ToString(“G”, CultureInfo.CurrentCulture) “0:00:02:09.0000000” timeRemaining.ToString(“t”, CultureInfo.CurrentCulture) “00:02:09” 我正在寻找一个简单的单行来以文化意识的方式输出timeSpan。 任何想法都表示赞赏。

全局设置String.Compare/ CompareInfo.Compare到Ordinal

我正在寻找一种策略,我可以将String.CompareTo的默认排序顺序设置为bytewise – ordinal。 我需要这样做,而无需在方法调用中指定sortorder。 我尝试了几种没有令人满意的结果的策略。 我得到了这个: CultureAndRegionInfoBuilder crib = new CultureAndRegionInfoBuilder(“foo”, CultureAndRegionModifiers.Neutral); CompareInfo compareInfo = new CustomCompareInfo(); crib.Register(); 在这个CustomCompareInfo中,我尝试覆盖默认的CompareInfo类,但遗憾的是这不能编译: The type ‘System.Globalization.CompareInfo’ has no constructors defined 我被困在这里。 感觉CompareInfo的自定义实现是我的问题的解决方案。 对此有什么想法? 编辑:我的问题的背景: 我正在研究的这个项目非常不寻常 – 一个巨大的代码库已经从其他编程语言转换为.NET。 在这种编程语言中,字符串比较默认为序数,这与.NET的差异导致转换后的代码库中出现错误,因此我认为如果我们能够将.NET配置为相同的默认行为,它将是最优雅的解决方案。 当然,可以使用比较说明符重新转换代码。 或者,我们可以引入一个执行序数(二进制)比较的扩展方法。 等等.. 但是,就我而言,从架构的角度来看,这些解决方案并不那么优雅。 这就是为什么我正在寻找一个解决方案,我可以在框架上全局设置这个序数比较。 提前致谢!