src/DotNetCommon.PinYin/WordsHelper.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/*
 * Copy from https://github.com/toolgood/ToolGood.Words.Pinyin
 * Copy from https://github.com/hotoo/pinyin
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using DotNetCommon.PinYin.Internals;

namespace DotNetCommon.PinYin
{
    /// <summary>
    /// 汉字转拼音帮助类,从 <see href="https://github.com/toolgood/ToolGood.Words.Pinyin"/> 处复制
    /// </summary>
    public static class WordsHelper
    {
        #region 拼音 操作
        /// <summary>
        /// 获取所有拼音,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证
        /// </summary>
        /// <param name="c">原文本</param>
        /// <param name="tone">是否带声调</param>
        /// <returns></returns>
        public static List<string> GetAllPinyin(char c, bool tone = false)
        {
            return PinyinDict.GetAllPinyin(c, tone ? 1 : 0);
        }

        /// <summary>
        /// 获取首字母,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证
        /// </summary>
        /// <param name="text">原文本</param>
        /// <returns></returns>
        public static string GetFirstPinyin(string text)
        {
            return PinyinDict.GetFirstPinyin(text, 0);
        }


        /// <summary>
        /// 获取拼音全拼,支持多音,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证
        /// </summary>
        /// <param name="text">原文本</param>
        /// <param name="tone">是否带声调</param>
        /// <returns></returns>
        public static string GetPinyin(string text, bool tone = false)
        {
            return string.Join("", PinyinDict.GetPinyinList(text, tone ? 1 : 0));
        }

        /// <summary>
        /// 获取拼音全拼,支持多音,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证
        /// </summary>
        /// <param name="text">原文本</param>
        /// <param name="splitSpan">分隔符</param>
        /// <param name="tone">是否带声调</param>
        /// <returns></returns>
        public static string GetPinyin(string text, string splitSpan, bool tone = false)
        {
后面还有 134 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。