Java简繁体中文互换

2021-01-25  本文已影响0人  CentForever

title: Java简繁体中文互换
date: 2019-11-18 17:40:50
categories:
- pinyin
tags:
- 简繁体


    implementation files('libs/jcc-bate-0.7.3.jar')
    implementation files('libs/ZHConverter.jar')
//简体转成繁体  s2t
    public static String s2t(String changeText) {
        try {
            JChineseConvertor jChineseConvertor = JChineseConvertor
                    .getInstance();
            changeText = jChineseConvertor.s2t(changeText);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                ZHConverter converter = ZHConverter.getInstance(ZHConverter.TRADITIONAL);
                changeText = converter.convert(changeText);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        return changeText;
    }

  //繁体转成简体
    public static String t2s(String changeText) {
        try {
            JChineseConvertor jChineseConvertor = JChineseConvertor
                    .getInstance();
            changeText = jChineseConvertor.t2s(changeText);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                ZHConverter converter = ZHConverter.getInstance(ZHConverter.SIMPLIFIED);
                changeText = converter.convert(changeText);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        return changeText;
    }
上一篇下一篇

猜你喜欢

热点阅读