1,2,3 ..."从西方阿拉伯数字&QUOT数字转换;东方阿拉伯数字" 1,2,3 ...." [英] Converting Numbers from Western Arabic Digits "1,2,3..." to Eastern Arabic Digits "١, ٢, ٣...."

查看:188
本文介绍了1,2,3 ..."从西方阿拉伯数字&QUOT数字转换;东方阿拉伯数字" 1,2,3 ...."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要存储在数据库中的日期转换为回历和显示相同的阿拉伯语

I need to convert date stored in database into Hijri and display the same in Arabic

我用文化来它确实日期转换,但它仍然显示日期为英文数字

I used the Culture to convert the date which it does but it still display date as English numbers


阳历日期19/01/2012 =
其Hirji相当于日期是25/02/1433

Example Gregorian Date = 19/01/2012 Its equivalent date in Hirji is 25/02/1433

继code段转换,但显示相同25/02/1433虽然我希望它在阿拉伯数字类似25/02/2012

Following code snippet converts but displays same as 25/02/1433 While i want it in Arabic numbers something like ٢٥/٠٢/٢٠١٢"

string sDate    
DateTime dtt = Convert.ToDateTime("19/01/2012");
CultureInfo ci = new CultureInfo("ar-SA");
sDdate = dtt.ToString("d", ci);

有没有被它转换日期为回历和阿拉伯语显示相同

Is there a was it converts date to Hijri and display same as Arabic

我需要这个,我在ASP.NET C#正在开发一个Web项目

I need this for a web project which i am developing in ASP.NET c#

推荐答案

CultureInfo类不会帮助你在任何解析或格式化的数字为阿拉伯语东部(0,1,2,3 ,4,5,6,7,8,9),也不至阿拉伯语西方(0,1,2,3,4, 5,6,7,8,9)。您必须手动转换它,这里是一个小功能,它会为你做一个整洁的方式:

The CultureInfo class will not help you in either parsing or formatting the numbers to eastern Arabic ("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩") nor to western Arabic ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"). You have to manually convert it, Here is a little function which will do that for you in a neat way:

public string ConvertToEasternArabicNumerals(string input)
    {
        System.Text.UTF8Encoding utf8Encoder = new UTF8Encoding();
        System.Text.Decoder utf8Decoder = utf8Encoder.GetDecoder();
        System.Text.StringBuilder convertedChars = new System.Text.StringBuilder();
        char[] convertedChar = new char[1];
        byte[] bytes = new byte[] { 217, 160 };
        char[] inputCharArray = input.ToCharArray();
        foreach (char c in inputCharArray)
        {
            if (char.IsDigit(c))
            {
                bytes[1] = Convert.ToByte(160 + char.GetNumericValue(c));
                utf8Decoder.GetChars(bytes, 0, 2, convertedChar, 0);
                convertedChars.Append(convertedChar[0]);
            }
            else
            {
                convertedChars.Append(c);
            }
        }
        return convertedChars.ToString();
    }

现在改变你的code有点像这样:

Now alter your code a little to look like this:

string sDate    
DateTime dtt = Convert.ToDateTime("19/01/2012");
CultureInfo ci = new CultureInfo("ar-SA");
sDate = ConvertToEasternArabicNumerals(dtt.ToString("dd/MM/yyyy", ci));

和事情会工作得很好。
顺便说一句,在code的作用是从<一个取href=\"http://weblogs.asp.net/abdullaabdelhaq/archive/2009/06/27/displaying-arabic-number.aspx\">here.

And things will work just fine. BTW, the code for the function was taken from here.

这篇关于1,2,3 ...&QUOT;从西方阿拉伯数字&QUOT数字转换;东方阿拉伯数字&QUOT; 1,2,3 ....&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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