java将数字替换为空_将数字替换为java中正确位置的单词

实际上我正试图用用户给出的句子中的数字替换为单词.本案例日期格式;例如:我的生日是在16/6/2000,我是

java的新手 – >成为—>我的生日是七月十六日,我是java的新手

这是代码:

Scanner reader = new Scanner(System.in);

System.out.println("Enter any numbers: ");

String nom = reader.nextLine(); // get input from user

//checking contains that has "/" or not

if(nom.contains("/")){

String parts[] = nom.split("[/]");

String part1 = parts[0]; //data before "/" will be stored in the first array

String day[] = part1.split("\\s+");// split between space

String get_day = day[day.length -1];// get last array

String get_month = parts[1]; //data in the between of "/" will be stored in the second array

String part3 = parts[2]; // data after "/" will be stored in the third array

String year[] = part3.split("\\s+");// split between space

String get_year = year[0];// get first array

String s = NumberConvert.convert(Integer.parseInt(get_day)) +

NumberConvert.convert(Integer.parseInt(get_month)) +

NumberConvert.convert(Integer.parseInt(get_year));

String con = nom.replaceAll("[0-9].*/[0-9].*/[0-].*", s); // replace number to word

System.out.println(con); // print the data already converted

} else {....}

但我得到的结果是:

My birthday is on sixteenth july two thousand

//"and I'm newbie to the java" is disappear [How to solve it]//

如何解决它.实际上我想获得“/”斜杠之前和之后的值并将其转换为单词并将其替换为来自用户的原始输入.

我试过的是:

String con = nom.replaceAll("[0-9].*/[0-9].*/[0-9999]", s); // a bit change [0-9].* to [0-9999]

但输出变成这样:

My birthday is on sixteenth july two thousand 000 and I'm newbie to the java

//after two thousand index "000" is appearing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值