using Microsoft.International.Converters.PinYinConverter; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.IO; using System.Linq; using System.Text; namespace test { class Program { /// <summary> /// 汉字转全拼 /// </summary> /// <param name="strChinese"></param> /// <returns></returns> public static string ConvertToAllSpell(string xsource) { var pinyins = new List<string>(); char ch; ChineseChar cc; for (int i = 0; i < xsource.Length; i++) { ch = xsource[i]; if (ChineseChar.IsValidChar(ch)) { cc = new ChineseChar(ch); pinyins.Add(cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList()[0]); } else { pinyins.Add(ch.ToString()); } //pinyins = pinyins.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower()); } return string.Join("", pinyins).ToLower(); } /// <summary> /// create_pinyin_img_rename(out var dic, out var arr); /// </summary> /// <param name="dic"></param> /// <param name="arr"></param> private static void create_pinyin_img_rename(out string dic, out string[] arr) { dic = @"C:\Users\Admin\Downloads\imgxxxx\"; arr = Directory.GetFiles(dic, "*"); foreach (var f in arr) { string x = f.Split(new[] {@"imgxxxx\"}, StringSplitOptions.None)[1].Replace(".png", ""); x = ConvertToAllSpell(x); File.Copy(f, @"C:\Users\Admin\Downloads\imgxxxx\renamed\" + x + ".png"); } } static void Main(string[] args) { Console.ReadKey(); } } }
标签:arr,ch,string,System,文件夹,中文名称,pinyins,using,图片 From: https://www.cnblogs.com/IBPM/p/17030114.html