读取文本中的数用英文转换过来-创新互联
前些天朋友公司的考试题,他们跟我说了,我没事做了做。简单的实现了一下。里面有的英文单词不对,不想改了,呵呵,反正就是这个意思。代码写的有点冗余,但功能还是实现了。不过只做了四位数的。
成都创新互联服务项目包括勃利网站建设、勃利网站制作、勃利网页制作以及勃利网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,勃利网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到勃利省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任! namespace CountNum
{
class Program
{
static void Main(string[] args)
{
Dictionary
Dictionary
Dictionary
//读取数字文本
string[] textNums = File.ReadAllLines("1.txt", Encoding.UTF8);
string[] saveTestEnglish = new string[textNums.Length];
for (int i = 0; i < textNums.Length; i++)
{
Match match = Regex.Match(textNums[i], @"\d[1-9]");
//int number = int.Parse(textNums[i]);
string number = textNums[i];
if (match.Success)
{
switch (number.Length)
{
case 1:
//个位数的英文读入
int ge = int.Parse(number);
saveTestEnglish[i] = dicGeEnglishGeWei[ge];
break;
case 2:
if (number[0] == '1')
{
int shi = int.Parse(number);
saveTestEnglish[i] = dicGetDuble[shi];
}
else
{
saveTestEnglish[i] = dicGetEnglishShiWei[SubS(number)] + dicGeEnglishGeWei[SubS((int.Parse(number) - 1).ToString())];
}
break;
case 3:
if (number[1] == '1')
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " hunred and" + dicGetDuble[int.Parse(number.Substring(1))];
}
else
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " hunred and" + dicGetEnglishShiWei[SubS(number.Substring(1))] + dicGeEnglishGeWei[SubS(number.Substring(2))];
}
break;
case 4:
if (number[2] == '1')
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " thousand " + dicGeEnglishGeWei[SubS(number.Substring(1))] + " hunred and" + dicGetDuble[int.Parse(number.Substring(2))];
}
else
{
saveTestEnglish[i] = dicGeEnglishGeWei[SubS(number)] + " thousand " + dicGeEnglishGeWei[SubS(number.Substring(1))] + " hunred and" + dicGetEnglishShiWei[SubS(number.Substring(2))] + dicGeEnglishGeWei[SubS(number.Substring(3))];
}
break;
default:
break;
}
}
else
{
saveTestEnglish[i] = "Error";
}
}
for (int j = 0; j < saveTestEnglish.Length; j++)
{
Console.WriteLine(saveTestEnglish[j]);
}
Console.Read();
}
///
/// 截取位数上的数
///
///
///
static int SubS(string num)
{
int danwei = 0;
danwei = int.Parse(num.Substring(0, 1));
return danwei;
}
///
///返回个位数字对应的英文
///
///
static Dictionary
{
#region 个位数字典
Dictionary
dicSingle.Add(1, " one");
dicSingle.Add(2, " two");
dicSingle.Add(3, " three");
dicSingle.Add(4, " four");
dicSingle.Add(5, " five");
dicSingle.Add(6, " six");
dicSingle.Add(7, " seven");
dicSingle.Add(8, " eight");
dicSingle.Add(9, " ine");
dicSingle.Add(0, "");
#endregion
return dicSingle;
}
static Dictionary
{
#region 个位数字典
Dictionary
dicSingle.Add(1, " ten");
dicSingle.Add(2, " twenty");
dicSingle.Add(3, " thirty");
dicSingle.Add(4, " forty");
dicSingle.Add(5, " fifty");
dicSingle.Add(6, " sixty");
dicSingle.Add(7, " seventy");
dicSingle.Add(8, " eighty");
dicSingle.Add(9, " ninty");
dicSingle.Add(0, "");
#endregion
return dicSingle;
}
static Dictionary
{
#region 个位数字典
Dictionary
dicSingle.Add(10, " ten");
dicSingle.Add(11, " eleven");
dicSingle.Add(13, " thirsteen");
dicSingle.Add(14, " fourteen");
dicSingle.Add(15, " fifteen");
dicSingle.Add(16, " sixteen");
dicSingle.Add(17, " seventeen");
dicSingle.Add(18, " eighteen");
dicSingle.Add(19, " nineteen");
dicSingle.Add(12, " twelve");
#endregion
return dicSingle;
}
}
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
网站题目:读取文本中的数用英文转换过来-创新互联
转载源于:http://myzitong.com/article/ceioes.html