zoukankan      html  css  js  c++  java
  • 由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);


    }

    }



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

  • 相关阅读:
    [atARC123F]Insert Addition
    3.1 概述
    2.5 信道的极限容量
    2.4 编码与调制
    2.3 传输方式
    tp6_004路由配置
    tp6_003多应用配置
    tp6_002规范和配置
    tp6_001安装和运行
    问题解决:tp6多应用无法获取controller 和 action怎么办
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4743221.html
Copyright © 2011-2022 走看看