public void TestMethod5() { var maxims = new string[] { "事常与人违,事总在人为", "骏马是跑出来的,强兵是打出来的", "驾驭命运的舵是奋斗。不抱有一丝幻想,不放弃一点机会,不停止一日努力。", "如果惧怕前面跌宕的山岩,生命就永远只能是死水一潭", "懦弱的人只会裹足不前,莽撞的人只能引为烧身,只有真正勇敢的人才能所向披靡" }; var expected = new string[] { "shi chang yu ren wei , shi zong zai ren wei", "jun ma shi pao chu lai de , qiang bing shi da chu lai de", "jia yu ming yun de duo shi fen dou 。 bu bao you yi si huan xiang , bu fang qi yi dian ji hui , bu ting zhi yi ri nu li 。", "ru guo ju pa qian mian die dang de shan yan , sheng ming jiu yong yuan zhi neng shi si shui yi tan", "nuo ruo de ren zhi hui guo zu bu qian , mang zhuang de ren zhi neng yin wei shao shen , zhi you zhen zheng yong gan de ren cai neng suo xiang pi mi" }; for (var i = 0; i < maxims.Length; i++) { var result = PinyinHelper.GetPinyin(maxims[i]); Assert.Equal <string>(expected[i].ToUpper(), result, this.comparer); } }
private void textBox1_TextChanged(object sender, EventArgs e) { label1.Text = PinyinHelper.GetPinyin(textBox1.Text); /*//清空文本字符串 * label1.Text = ""; * //获取用户输入的字符串 * string txt = textBox1.Text; * //逐个遍历字符,获取对应的拼音 * foreach (char c in txt) * { * //判断指定的字符,是否是汉字 * if (ChineseChar.IsValidChar(c)) * { * //是汉字,则构造字符对象 * ChineseChar cc = new ChineseChar(c); * //拼接返回的是集合,因为存在多音字的情况 * //foreach (var c1 in cc.Pinyins) * //{ * // label1.Text += c1 + " "; * //} * //获取拼音首字母 * label1.Text += cc.Pinyins[0][0]; * } * else label1.Text += c;//不是汉字,直接拼接 * * }*/ }
public static List <string> GetSiteNames(string strKeyWord) { List <string> list = new List <string>(); int iISMajorVersion = IISHelper.GetIISMajorVersion(); if (iISMajorVersion == 6) { ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("root\\MicrosoftIISv2", "SELECT * FROM IIsWebServerSetting"); using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator()) { while (enumerator.MoveNext()) { ManagementObject managementObject = (ManagementObject)enumerator.Current; list.Add(managementObject["ServerComment"].ToString()); } } } else { ServerManager serverManager = new ServerManager(); foreach (Site current in serverManager.Sites) { if (current.Name.ToUpper().Contains(strKeyWord.ToUpper()) || PinyinHelper.GetPinyin(current.Name).ToUpper().Contains(strKeyWord.ToUpper()) || PinyinHelper.GetFirstPinyin(current.Name).ToUpper().Contains(strKeyWord.ToUpper())) { list.Add(current.Name); } } } return(list); }
static void Main(string[] args) { var maxims = new string[] { "事常与人违,事总在人为", "骏马是跑出来的,强兵是打出来的", "驾驭命运的舵是奋斗。不抱有一丝幻想,不放弃一点机会,不停止一日努力。", "如果惧怕前面跌宕的山岩,生命就永远只能是死水一潭", "懦弱的人只会裹足不前,莽撞的人只能引为烧身,只有真正勇敢的人才能所向披靡" }; var expected = new string[] { "shi chang yu ren wei , shi zong zai ren wei", "jun ma shi pao chu lai de , qiang bing shi da chu lai de", "jia yu ming yun de duo shi fen dou 。 bu bao you yi si huan xiang , bu fang qi yi dian ji hui , bu ting zhi yi ri nu li 。", "ru guo ju pa qian mian die dang de shan yan , sheng ming jiu yong yuan zhi neng shi si shui yi tan", "nuo ruo de ren zhi hui guo zu bu qian , mang zhuang de ren zhi neng yin wei shao shen , zhi you zhen zheng yong gan de ren cai neng suo xiang pi mi" }; for (var i = 0; i < maxims.Length; i++) { var result = PinyinHelper.GetPinyin(maxims[i]); Console.WriteLine($"{maxims[i]} = {result}"); } Console.ReadKey(); }
public static string GetPinyin(string str) { var sb = new StringBuilder(); sb.Append(PinyinHelper.GetPinyin(str)); sb.Append(" "); sb.Append(PinyinHelper.GetPinyinInitials(str)); return(CleanUpSpaces(sb.ToString())); }
public static Dictionary <string, SiteObj> GetSiteNames() { Dictionary <string, SiteObj> dictionary = new Dictionary <string, SiteObj>(); int iISMajorVersion = IISHelper.GetIISMajorVersion(); if (iISMajorVersion == 6) { ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("root\\MicrosoftIISv2", "SELECT * FROM IIsWebServerSetting"); using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator()) { while (enumerator.MoveNext()) { ManagementObject managementObject = (ManagementObject)enumerator.Current; SiteObj siteObj = new SiteObj(); siteObj.SiteName = managementObject["ServerComment"].ToString(); siteObj.SiteNameQuanPin = PinyinHelper.GetPinyin(siteObj.SiteName).ToUpper(); siteObj.SiteNameDuanPin = PinyinHelper.GetFirstPinyin(siteObj.SiteName).ToUpper(); siteObj.PoolName = managementObject["AppPoolId"].ToString(); ManagementBaseObject[] array = (ManagementBaseObject[])managementObject["ServerBindings"]; siteObj.Port = array[0]["Port"].ToString(); int num = 0; while (dictionary.ContainsKey(siteObj.SiteName)) { num++; siteObj.SiteName = managementObject["ServerComment"].ToString() + "_" + num.ToString(); } dictionary.Add(siteObj.SiteName, siteObj); } } } else { ServerManager serverManager = new ServerManager(); foreach (Site current in serverManager.Sites) { SiteObj siteObj = new SiteObj(); siteObj.SiteName = current.Name; siteObj.SiteNameQuanPin = PinyinHelper.GetPinyin(siteObj.SiteName).ToUpper(); siteObj.SiteNameDuanPin = PinyinHelper.GetFirstPinyin(siteObj.SiteName).ToUpper(); siteObj.PoolName = ((current.Applications.Count > 0) ? current.Applications[0].ApplicationPoolName : ""); siteObj.Port = current.Bindings[0].EndPoint.Port.ToString(); siteObj.SitePath = ((current.Applications.Count > 0) ? current.Applications[0].VirtualDirectories[0].PhysicalPath : ""); int num = 0; while (dictionary.ContainsKey(siteObj.SiteName)) { num++; siteObj.SiteName = current.Name + "_" + num.ToString(); } dictionary.Add(siteObj.SiteName, siteObj); } } return(dictionary); }
public void CHSToPinyinTest() { string[] maxims = new string[] { "事常与人违,事总在人为", "骏马是跑出来的,强兵是打出来的", "驾驭命运的舵是奋斗。不抱有一丝幻想,不放弃一点机会,不停止一日努力。 ", "如果惧怕前面跌宕的山岩,生命就永远只能是死水一潭", "懦弱的人只会裹足不前,莽撞的人只能引为烧身,只有真正勇敢的人才能所向披靡", "重庆唉" }; string[] medicines = new string[] { "聚维酮碘溶液", "开塞露", "炉甘石洗剂", "苯扎氯铵贴", "鱼石脂软膏", "莫匹罗星软膏", "红霉素软膏", "氢化可的松软膏", "曲安奈德软膏", "丁苯羟酸乳膏", "双氯芬酸二乙胺乳膏", "冻疮膏", "克霉唑软膏", "特比奈芬软膏", "酞丁安软膏", "咪康唑软膏、栓剂", "甲硝唑栓", "复方莪术油栓" }; String maximsPinyin = ""; foreach (string s in maxims) { maximsPinyin += PinyinHelper.GetPinyin(s, " "); } String medicinesPinyin = ""; foreach (string m in medicines) { medicinesPinyin += PinyinHelper.GetPinyin(m, " "); } Assert.IsNotNull(medicinesPinyin); }
private void textBox1_Leave(object sender, EventArgs e) { #region 拼音基础 ////构造拼音对象 //ChineseChar cc = new ChineseChar(textBox1.Text[0]); ////调用获取拼音的属性 //var pinyin = cc.Pinyins;//返回一个字符串集合 ////一个字的拼音结果,就是(拼音+声调) ////是集合的原因:中文存在多音字 ////输出集合中的元素 //foreach (string s in pinyin) //{ // textBox2.Text += s + " "; //} #endregion #region 获取中文首字母 //string txt = textBox1.Text; ////字符串可以被看作是字符数组 //foreach (char c in txt) //{ // ChineseChar cc=new ChineseChar(c); // string py1 = cc.Pinyins[0];//多音字中的第一个拼音 // char c1 = py1[0]; //获取首字母 // textBox2.Text += c1; //} #endregion #region 调用封装帮助类 textBox2.Text = PinyinHelper.GetPinyin(textBox1.Text); #endregion }
public void TestMethod3() { var result = PinyinHelper.GetPinyin("我们都有一个家", "|"); Assert.AreEqual <string>("WO|MEN|DOU|YOU|YI|GE|JIA", result); }
public void TestMethod1() { var result = PinyinHelper.GetPinyin('中'); Assert.Equal("ZHONG", result, this.comparer); }
private void textXmt_Leave(object sender, EventArgs e) { textpy.Text = PinyinHelper.GetPinyin(textXmt.Text); }
public void TestMethod2() { var result = PinyinHelper.GetPinyin('的'); Assert.Equal <string>("DE", result, this.comparer); }
private void textBox1_Leave(object sender, EventArgs e) { textBox2.Text = PinyinHelper.GetPinyin(textBox1.Text); }
/// <summary> /// 得到汉字首字母大写字符串 /// </summary> /// <param name="str"></param> /// <returns></returns> public string GetChar(string str) { return(PinyinHelper.GetPinyin(str)); }
private void txtNameAdd_Leave(object sender, EventArgs e) { txtPinyin.Text = PinyinHelper.GetPinyin(txtNameAdd.Text); }
private void txtTitleSave_Leave(object sender, EventArgs e) { txtChar.Text = PinyinHelper.GetPinyin(txtTitleSave.Text); }
public void TestMethod2() { var result = PinyinHelper.GetPinyin('的'); Assert.AreEqual <string>("DE", result); }
public void TestMethod1() { var result = PinyinHelper.GetPinyin('中'); Assert.AreEqual <string>("ZHONG", result); }
static string GetPinyin(string str, string separator) => PinyinHelper.GetPinyin(str, separator) ?? string.Empty;
public void TestPinyin() { var pinyin = PinyinHelper.GetPinyin("我是中国人", false); }
/// <summary> /// 生成的拼音不包含声调,均为大写 /// 中国 - ZHONGGUO /// </summary> /// <param name="text"></param> /// <param name="separator"></param> /// <returns></returns> public static string GetPinyin(string text, string separator = ",") { return(PinyinHelper.GetPinyin(text, separator)); }