0
点赞
收藏
分享

微信扫一扫

字符串反转代码

题目如下:

ADR6H9UGO4MUJ2H8OF.png

代码:

```c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Day06
{
class Program
{
static void Main(string[] args)
{
string str = "How are you";
//1
string[] str1 = str.Split(' ');
for (int i = str1.Length - 1; i >= 0; i--)
{
Console.Write(str1[i]);
Console.Write(" ");
}
Console.WriteLine();
//2
for (int i = str1.Length - 1; i >= 0; i--)
{
for (int j = str1[i].Length - 1; j >= 0; j--)
Console.Write(str1[i][j]);
Console.Write(" ");
}
//3
Console.WriteLine();
str = str.Trim();
for (int i = 0;i<str.Length ;i++ ) {
int a = str.IndexOf(str[i]);
int b = str.LastIndexOf(str[i]);
if (a == b)
Console.Write(str[i]+" ");
}
}

}

}


## 运行结果:
![image.png](https://s2.51cto.com/images/20220705/1656951562435861.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
## 注意事项:
1.==Split方法返回的数组可以理解为交错数组(一维数组里面包含着一维数组)。==
2.这三道题考察的是对string相关方法的理解和运用,以下列出几个常用的string方法
## ToArray   Insert   Contains  Tolower   ToUpper   IndexOf   Substring  Trim   Replace   Join  
举报

相关推荐

0 条评论