如何转换波斯位数变量英语使用数字文化? [英] How to Convert Persian Digits in variable to English Digits Using Culture?

查看:178
本文介绍了如何转换波斯位数变量英语使用数字文化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要改变中保存的变量这样的波斯数字:

 字符串值=1036751; 



 字符串值=1036751; 



我如何用简单的方法类似的文化信息,以做到这一点吗?



我的示例代码:

 列表<串GT; NERKHCOlist =新的List<串GT;(); 
NERKHCOlist = ScrappingFunction(NERKHCO,NERKHCOlist);
INT NERKHCO_Price = int.Parse(NERKHCOlist [0]); // NERKHCOlist [0] = 1036751

< =因此,它可以不分析它来诠释结果
,这是在我的函数retun里面列表项的波斯数字



名单

 保护名单,LT;字符串> ScrappingFunction(字符串SiteAddress,列表与LT;字符串> NodesList)
{
串价=空;
名单,LT;字符串>目标=新的List<串GT;();
的foreach(在NodesList VAR路径)
{
HtmlNode节点= document.DocumentNode.SelectSingleNode(path.ToString()); //识别目标节点
价格= node.InnerHtml ; //把目标节点的文本变量(波斯语位)
Targets.Add(价格);
}
回报率的目标;
}


解决方案

 私有静态只读串[] PN = {0,1,2,3,4,5,6,7,8,9 }; 
私人静态只读串[]烯= {0,1,2,3,4,5,6,7,8, 9};
公共静态字符串ToPersianNumber(此字符串strNum)
{
串chash = strNum;
的for(int i = 0;我小于10;我++)
chash = chash.Replace(EN [I],PN [I]);
返回chash;
}
公共静态字符串ToPersianNumber(这INT intNum)
{
串chash = intNum.ToString();
的for(int i = 0;我小于10;我++)
chash = chash.Replace(EN [I],PN [I]);
返回chash;
}



运行这段代码:

 字符串strNum =01974365; 
INT intNum = 97310612;

串OUT1 = strNum.ToPersianNumber();
串OUT2 = intNum.ToPersianNumber();

您可以将此部分用于转换的波斯更改为英语数字:

  chash = chash.Replace(EN [I],PN [I]); 



  chash = chash.Replace(PN [I],连接[I]); 


I want to change persian numbers which are saved in variable like this :

string Value="۱۰۳۶۷۵۱"; 

to

string Value="1036751";

How can I use easy way like culture info to do this please?

my sample code is:

List<string> NERKHCOlist = new List<string>();
NERKHCOlist = ScrappingFunction(NERKHCO, NERKHCOlist);
int NERKHCO_Price = int.Parse(NERKHCOlist[0]);//NERKHCOlist[0]=۱۰۳۶۷۵۱ 

<= So it can not Parsed it to int
And This is in my function which retun a list with persian digits inside list items

protected List<string> ScrappingFunction(string SiteAddress, List<string> NodesList)
{    
    string Price = "null";
    List<string> Targets = new List<string>();
    foreach (var path in NodesList)
    {
        HtmlNode node = document.DocumentNode.SelectSingleNode(path.ToString());//recognizing Target Node
        Price = node.InnerHtml;//put text of target node in variable(PERSIAN DIGITS)
        Targets.Add(Price);
    }
    return Targets;
}

解决方案

   private static readonly string[] pn = { "۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹" };
   private static readonly string[] en = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
   public static string ToPersianNumber(this string strNum)
   {
       string chash = strNum;
       for (int i = 0; i < 10; i++)
           chash = chash.Replace(en[i], pn[i]);
       return chash;
   }
   public static string ToPersianNumber(this int intNum)
   {
       string chash = intNum.ToString();
       for (int i = 0; i < 10; i++)
           chash = chash.Replace(en[i], pn[i]);
       return chash;
   }

run this code:

string strNum = "01974365";
int intNum = 97310612;

string out1 = strNum.ToPersianNumber();
string out2 = intNum.ToPersianNumber();

you can change this part for convert Persian to English numbers:

chash = chash.Replace(en[i], pn[i]);

to

chash = chash.Replace(pn[i], en[i]);

这篇关于如何转换波斯位数变量英语使用数字文化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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