GithubHelp home page GithubHelp logo

stonewallzzz / pinyin4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from open-android/pinyin4j

0.0 2.0 0.0 387 KB

A copy of http://sourceforge.net/projects/pinyin4j, then deploy it to maven central repository.

Java 99.74% HTML 0.26%

pinyin4j's Introduction

开源项目pinyin4j使用简介

pinyin4j这个java库方便实现将汉字转换拼音

开源地址:https://github.com/open-android/pinyin4j

使用效果

(重)--(chong2/zhong4) (好)--(HĂO/HÀO)

使用步骤

1. 在project的build.gradle添加如下代码(如下图)

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

2. 在Module的build.gradle添加依赖

compile 'com.github.open-android:pinyin4j:2.5.0'

3.演示步骤

  • 将演示代码复制到Activity的onCreate方法中

      //-------------------默认格式转换-----------------------------
      String[] pyStrs = PinyinHelper.toHanyuPinyinStringArray('重');
    
      for (String s : pyStrs) {
          System.out.println(s);
      }
    
    
    
      //-------------------指定格式转换----------------------------
      HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    
      // UPPERCASE:大写  (ZHONG)
      // LOWERCASE:小写  (zhong)
      format.setCaseType(HanyuPinyinCaseType.UPPERCASE);//输出大写
    
      // WITHOUT_TONE:无音标  (zhong)
      // WITH_TONE_NUMBER:1-4数字表示音标  (zhong4)
      // WITH_TONE_MARK:直接用音标符(必须WITH_U_UNICODE否则异常)  (zhòng)
      format.setToneType(HanyuPinyinToneType.WITH_TONE_MARK);
    
      // WITH_V:用v表示ü  (nv)
      // WITH_U_AND_COLON:用"u:"表示ü  (nu:)
      // WITH_U_UNICODE:直接用ü (nü)
      format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
    
      String[] hao = PinyinHelper.toHanyuPinyinStringArray('好', format);
    
      for (String s : hao) {
          System.out.println(s);
      }
    

注意捕获BadHanyuPinyinOutputFormatCombination异常

  • 更多干货请下载app

黑马助手.png

  • 欢迎关注微信公众号

pinyin4j's People

Contributors

belerweb avatar obiteaaron avatar open-android avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.