c# 多字符替换 多音字

private Dictionary<string, string> substitutions { get; set; } = new Dictionary<string, string>();//多音字替换
 //多音字转换
                var pattern = string.Join("|", substitutions.Keys.Select(Regex.Escape));
                var result = Regex.Replace(str, pattern, match => substitutions[match.Value]);
"Polyphone": {
    "text": "翟查郇盖曾乐华单仇重朴相解应繁要覃员都能瞿",
    "pronunciation": "宅渣环葛增月话善求虫瓢像谢硬婆腰勤云督耐劬"
  }
 var polyphonetext = configuration["Polyphone:text"].ToString().ToArray();
            var polyphonepronunciation = configuration["Polyphone:pronunciation"].ToString().ToArray();
            for(var i = 0; i < polyphonetext.Length; i++)
            {
                substitutions.Add(polyphonetext[i].ToString(), polyphonepronunciation[i].ToString());
            }

 

posted @ 2023-04-13 11:35  天天的蓝色  阅读(31)  评论(0编辑  收藏  举报