码迷,mamicode.com
首页 > 数据库 > 详细

JAVA、SQL server不支持英文音标,针对[]里音标进行替换

时间:2015-08-10 01:54:02      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class zhybTest {
    public static void main(String[] args) {
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("A0", "?");
        map.put("A1", "?");
        map.put("A2", "?");
        map.put("A3", "æ");
        map.put("A4", "?");
        map.put("A5", "?");
        map.put("A6", "?");
        map.put("A7", "?");
        map.put("A8", "?");
        map.put("A9", "ð");
        map.put("A10", "?");
        map.put("A11", "?");
        map.put("A12", "?");
        String str="☆bassinet [,bæs?‘net] n. 摇篮摇篮也可以叫cradle [‘kre?d(?)l]。BUT!cradle这个词还有另一个意思,我们来看个例句:啊!黄河!The cradle of Chinese nation! 没错,就是发源地的意思啦~";
        String txt=str;//把str的字符串交给txt先
        List list_false=new ArrayList();//只存未转的音标
        List list_true=new ArrayList();//只存已转的音标
        while (str.indexOf("[")>0&&str.indexOf("]")>0) {
            String str_a=str.substring(str.indexOf("[")+1, str.indexOf("]"));
            //System.out.println("未转换前---------->"+str_a);
            list_false.add(str_a);
            for(int i=0;i<map.size();i++){
                //首先找字符串是否存在map里的特殊字符
                if(str_a.indexOf(map.get("A"+i).toString())>0){
                    //下面就是把特殊字符转化为map的key
                    if(map.get("A"+i).toString().equals(str_a.substring(str_a.indexOf(map.get("A"+i).toString()), str_a.indexOf(map.get("A"+i).toString())+1))){
                        //System.out.println(map.get("A"+i)+"转为--->"+"A"+i);
                        str_a=str_a.replace(map.get("A"+i).toString(), "A"+i);
                        //System.out.println("转化后的结果---------->"+str_a);
                    }
                }
            }
            //System.out.println("已转换后---------->"+str_a);
            list_true.add(str_a);//每次转换后存入list
            str=str.substring(str.indexOf("]")+1,str.length());
        }
        for(int i=0;i<list_false.size();i++){
            txt=txt.replace(list_false.get(i).toString(), list_true.get(i).toString());
        }
        System.out.println("打印出来————————>"+txt);
    }
}

希望能帮到大家,大家记得留评语呀~        O(∩_∩)O

JAVA、SQL server不支持英文音标,针对[]里音标进行替换

标签:

原文地址:http://www.cnblogs.com/xujinqiang/p/4716854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!