//字符转翻转“I am a student”
namespace Split
{
class Program
{
static void Main(string[] args)
{
string A = “I am a student”;
string[] arr = A.Split(’ ');
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(“翻转前”+arr[i]);
}
for (int i = 0; i < arr.Length/2; i++)
{
string temp = arr[i];
arr[i] = arr[arr.Length - i-1];
arr[arr.Length - i-1] = temp;
}
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(“翻转后”+arr[i]);
}
Console.ReadKey();
}
}
}

C#字符串翻转
最新推荐文章于 2025-01-17 16:43:12 发布
博客给出了字符串翻转的代码示例,以字符串“I am a student”为例,通过Split方法分割字符串,再使用循环交换元素位置实现翻转,并输出翻转前后的结果。

3388

被折叠的 条评论
为什么被折叠?



