- string str = "my love";//可改Console.ReadKey();
- //分割字符串,以空格作为分隔符
- string[] strs = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < strs.Length; i++)
- {
- //遍历字符串数组
- string strNew = "";
- for (int j = strs[i].Length-1; j >=0 ; j--)
- {
- //实现字符串反序
- strNew += (strs[i][j]).ToString();
- }
- strs[i] = strNew;//将反序后的字符串赋值回给字符串数组
- }
- string res = String.Join(" ",strs);//用用空格拼接字符串
- Console.WriteLine(res);
- Console.ReadKey();
复制代码
按你要求写了下,这是代码和注释 |