在开发过程中,将开发过程中经常用的一些代码片段做个记录,下面资料是关于C#检索出一个字符串中某字符第n次出现的位置(IndexOf)的代码,应该是对各位有较大用处。
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Please input your STRING:”);
string a = Console.ReadLine();
char c;
char find_c;
Console.WriteLine(“Please input the CHARACTER in your string:”);
find_c = Convert.ToChar(Console.ReadLine());
int count = 0;
for (int i = 0; i < a.Length; i++)
{
c = a[i];
{
count++;
}
}
Console.WriteLine(“There are total {0} of char ‘{1}’ in your input string.”,count,find_c);
int index = 0;
Console.WriteLine(“Please input the SEQUENCE of the char ‘{0}’ in your input string:”, find_c);
n = Convert.ToInt32(Console.ReadLine());
if (n > count)
{
Console.WriteLine(“Error:The Num must be l
C#检索出一个字符串中某字符第n次出现的位置(IndexOf)的代码
最新推荐文章于 2024-08-08 23:37:45 发布
本文提供了一段C#代码,用于检索字符串中特定字符第n次出现的位置,通过用户输入字符串、目标字符和序列号实现。
摘要由CSDN通过智能技术生成