Skip to content

Commit 334e88b

Browse files
committed
refactor: 增加拼音服务
1 parent 894c420 commit 334e88b

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/components/BootstrapBlazor.Region/Services/PinYinService.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,29 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5+
using System.Text;
6+
57
namespace BootstrapBlazor.Components;
68

7-
class PinYinService
9+
static class PinYinService
810
{
9-
public static Dictionary<string, string> codes = new()
11+
public static string GetFirstLetters(string text)
12+
{
13+
var ret = new StringBuilder();
14+
foreach (var c in text)
15+
{
16+
foreach (var item in Cache)
17+
{
18+
if (item.Value.Contains(c, StringComparison.InvariantCulture))
19+
{
20+
ret.Append(item.Key.First());
21+
}
22+
}
23+
}
24+
return ret.ToString().ToUpperInvariant();
25+
}
26+
27+
public static Dictionary<string, string> Cache = new()
1028
{
1129
{ "a", "阿啊吖嗄腌锕" },
1230
{ "ai", "爱埃碍矮挨唉哎哀皑癌蔼艾隘捱嗳嗌嫒瑷暧砹锿霭" },
@@ -46,7 +64,7 @@ class PinYinService
4664
{ "chen", "陈沉称衬尘臣晨郴辰忱趁伧谌谶抻嗔宸琛榇碜龀" },
4765
{ "cheng", "成程称城承乘呈撑诚橙惩澄逞骋秤丞埕噌枨柽塍瞠铖铛裎蛏酲" },
4866
{ "chi", "持尺齿吃赤池迟翅斥耻痴匙弛驰侈炽傺坻墀茌叱哧啻嗤彳饬媸敕眵鸱瘛褫蚩螭笞篪豉踟魑" },
49-
{ "chong", "虫充冲崇宠茺忡憧铳舂艟" },
67+
{ "chong", "虫重充冲崇宠茺忡憧铳舂艟" },
5068
{ "chou", "抽仇臭酬畴踌稠愁筹绸瞅丑俦帱惆瘳雠" },
5169
{ "chu", "出处除初础触楚锄储橱厨躇雏滁矗搐亍刍怵憷绌杵楮樗褚蜍蹰黜" },
5270
{ "chuai", "揣搋啜膪踹" },

0 commit comments

Comments
 (0)