文件中字符替换该怎么做!!!
文件内容 :
这个价值为1美元,但这个为12美元。
变量名为 file1。
110 是一个数字。
要替换后的效果:
这个价值为一美元,但这个为十二美元。
变量名为 file1。
110 是一个数字
替换依据为map映射:
map.put(0,"零");
map.put(1,"一");
map.put(2,"二");
map.put(3,"三");
map.put(4,"四");
map.put(5,"五");
map.put(6,"六");
map.put(7,"七");
map.put(8,"八");
map.put(9,"九");
map.put(10,"十");
map.put(11,"十一");
map.put(12,"十二");
[b][color=#FF0000]将文件中和map key相同的数值替换成map的value。
来个大神帮帮我哇!
这个价值为1美元,但这个为12美元。
变量名为 file1。
110 是一个数字。
要替换后的效果:
这个价值为一美元,但这个为十二美元。
变量名为 file1。
110 是一个数字
替换依据为map映射:
map.put(0,"零");
map.put(1,"一");
map.put(2,"二");
map.put(3,"三");
map.put(4,"四");
map.put(5,"五");
map.put(6,"六");
map.put(7,"七");
map.put(8,"八");
map.put(9,"九");
map.put(10,"十");
map.put(11,"十一");
map.put(12,"十二");
[b][color=#FF0000]将文件中和map key相同的数值替换成map的value。
public class Solution {
public static Map<Integer, String> map = new HashMap<Integer, String>();
static {
map.put(0,"零");
map.put(1,"一");
map.put(2,"二");
map.put(3,"三");
map.put(4,"四");
map.put(5,"五");
map.put(6,"六");
map.put(7,"七");
map.put(8,"八");
map.put(9,"九");
map.put(10,"十");
map.put(11,"十一");
map.put(12,"十二");
}
public static void main(String[] args)throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
FileReader fis = new FileReader(name);
BufferedReader file = new BufferedReader(fis);
String tem = null;
while (file.ready()){
tem = file.readLine();
for(Map.Entry<Integer,String>pair : map.entrySet()) {
tem = tem.replace("*.\\b" +pair.getKey().intValue()+"*.\\b", pair.getValue());
}
System.out.println(tem);
}
reader.close();
file.close();
}
}
来个大神帮帮我哇!
...全文
相关推荐
bat文件 字符串提取&替换等操作
bat文件 字符串提取以及替换等操作 在dos窗口下运行 供学习参考
批量替换文件名中的字符
可以批量替换文件名中的特殊字符,例如替换文件名中“#”为空。
批量替换文件中的字符
改工具是用idea编写的java小工具,改工具是批量替换文件夹下所有目标字符串为指定字符串,代码采用递归查找文件,文件流读写操作字符串供大家学习使用。也可以自己打成jar包脚本运行。注意:需要有java环境
替换文件中指定字符串_批处理工具
一个批处理工具,可自动替换某文件中指定的字符串为用户输入的
替换一个文本文件中的字符串
输入参数:a待替换文件的路径、b需要替换的字符串、c进行替换的字符串,功能:将文件A中的b替换为c。


Java SE
