由Lucnene 对于预治疗的文字,全角半角转换器(可执行)
這是我第二次讀這本書,在自己的學習之間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);
}
}
版權聲明:本文博客原創文章,博客,未經同意,不得轉載。
轉載于:https://www.cnblogs.com/mfrbuaa/p/4743221.html
總結
以上是生活随笔為你收集整理的由Lucnene 对于预治疗的文字,全角半角转换器(可执行)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决虚拟机linux端mysql数据库无
- 下一篇: Android 开发工具类 36_ ge