且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

由Lucnene 对于预治疗的文字,全角半角转换器(可执行)

更新时间:2022-08-22 17:02:27

这是我第二次读这本书,在自己的学习之间XML,javascript,的深入研究《JAVA 核心技术》。

在当中深入的学习了java的非常多机制。

回头再来看搜索引擎这本书的时候。就认为比第一次好非常多了。


这个是代码,能够执行,

假设想自己定义的话,那就把str1= " ";

中间的字符串改动。


JAVA代码:


package com;


import java.util.HashMap;


import org.xml.sax.HandlerBase;


public class Replace {
public static String replace(String line){

//创建一个HashMap存储全角和半角字符之间的相应关系
HashMap map = new HashMap();
map.put("。", ",");
map.put("。", ".");
       map.put("〈", "<");
       map.put("〉", ">");
       map.put("|", "|");
       map.put("《", "<");
       map.put("》", ">");
       map.put("[", "[");
       map.put("]", "]");
       map.put("?", "?");
       map.put(""", "\"");
       map.put(":", ":");
       map.put("﹑", ",");
       map.put("(", "(");
       map.put(")", ")");
       map.put("【", "[");
       map.put("】", "]");
       map.put("-", "-");
       map.put(" ̄", "~");
       map.put("!", "!");
       map.put("`", "`");
       map.put("1", "1");
       map.put("2", "2");
       map.put("3", "3");
       map.put("4", "4");
       map.put("5", "5");
       map.put("6", "6");
       map.put("7", "7");
       map.put("8", "8");
       map.put("9", "9");
       
       int length = line.length();
       for(int i = 0; i < length; i++){
         String charat = line.substring(i, i + 1);
         if(map.get(charat) != null){
         line = line.replace(charat, (String)map.get(charat));
         }
       }
       return line;

}
public static void main(String[] args) {
// TODO Auto-generated method stub
Replace a = new Replace();
String str1 = "1111";
String str2;
str2 = replace(str1);
System.out.println("转换后是: " + str2);


}

}



版权声明:本文博客原创文章,博客,未经同意,不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4743221.html,如需转载请自行联系原作者