110,536
社区成员
发帖
与我相关
我的任务
分享
string[] strNum = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string strYour = "锦江区红星路一段四十四号";
strYour = Regex.Replace(strYour, "[十百千万]", "");
strYour = Regex.Replace(strYour, "[一二三四五六七八九零]",
delegate(Match m) { return (strNum as IList<string>).IndexOf(m.Value).ToString(); });
MessageBox.Show(strYour);
string[] strNum = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string strYour = "锦江区红星路一段四十四号";
strYour = Regex.Replace(strYour, "(?<=[^一二三四五六七八九零]|^)十(?=[^一二三四五六七八九零]|$)", "10");
strYour = Regex.Replace(strYour, "[十百千万亿兆]", "");
strYour = Regex.Replace(strYour, "[一二三四五六七八九零]",
delegate(Match m) { return (strNum as IList<string>).IndexOf(m.Value).ToString(); });
MessageBox.Show(strYour);
string[] strNum = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string strYour = "锦江区红星路一段四十四号";
strYour = Regex.Replace(strYour, "(?<=[^一二三四五六七八九零]|^)十(?=[^一二三四五六七八九零]|$)", "10");
strYour = Regex.Replace(strYour, "[十百千万]", "");
strYour = Regex.Replace(strYour, "[一二三四五六七八九零]",
delegate(Match m) { return (strNum as IList<string>).IndexOf(m.Value).ToString(); });
MessageBox.Show(strYour);
private string UperNumberToLower(string srcStr)
{
srcStr = Regex.Replace(srcStr, @"(?<![零一二三四五六七八九])十", "一十");
srcStr = Regex.Replace(srcStr, @"十(?![零一二三四五六七八九])", "十零");
return Regex.Replace(srcStr, @"(?![万千百])[零一二三四五六七八九十百千万]+", new MatchEvaluator(UpToLowerDelegate));
}
private string UpToLowerDelegate(Match m)
{
string uNumber = m.Value;
int total = 0;
int unit = -1;
int standNum = -1;
List<string> listNum = new List<string>(new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" });
List<string> listUnit = new List<string>(new string[] { "十", "百", "千", "万" });
List<int> listInt = new List<int>(new int[] { 10, 100, 1000, 10000 });
for (int i = 0; i < uNumber.Length;i++ )
{
string strChar = uNumber[i].ToString();
if (listNum.IndexOf(strChar) > -1)
standNum = listNum.IndexOf(strChar);
if (listUnit.IndexOf(strChar) > -1)
{
if (listUnit.IndexOf(strChar) < unit)
total = total + standNum * listInt[listUnit.IndexOf(strChar)];
else
{
total = (total + standNum) * listInt[listUnit.IndexOf(strChar)];
unit = listUnit.IndexOf(strChar);
}
standNum = -1;
}
if (i == uNumber.Length - 1 && standNum != -1)
total = total + standNum;
}
return total.ToString();
}
richTextBox2.Text = UperNumberToLower("锦江区红星路一段二十万一千零二号");