- string str="w我a爱h黑m马c程x序y员";
- char[] zimu = { 'w', 'a', 'h', 'm', 'c', 'x', 'y' };
- char [] hanzi={'我','爱','黑','马','程','序','员'};
- string strZm="abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//字母字符串
- List<char> zimuList = new List<char>();
- List<char> hanziList = new List<char>();
-
- for (int i = 0; i < str.Length; i++)
- {
- if (strZm.Contains(str[i]))//如果包含,则分到字母zimuList否则分到hanziList
- {
- zimuList.Add(str[i]);
- }
- else
- {
- hanziList.Add(str[i]);
- }
- }
- char[]newzimu=new char[zimuList.Count];//定义新的数组
- char[]newhanzi=new char[hanziList.Count];
- for (int i = 0; i < newzimu.Length; i++)
- {
- newzimu[i]=zimuList[i];
- Console.WriteLine(newzimu[i]);
- }
- for (int i = 0; i < newhanzi.Length; i++)
- {
- newhanzi[i] = hanziList[i];
- Console.WriteLine(newhanzi[i]);
- }
- Console.ReadKey();
复制代码 |