C#检索出一个字符串中某字符第n次出现的位置(IndexOf)的代码

本文提供了一段C#代码,用于检索字符串中特定字符第n次出现的位置,通过用户输入字符串、目标字符和序列号实现。
摘要由CSDN通过智能技术生成

在开发过程中,将开发过程中经常用的一些代码片段做个记录,下面资料是关于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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值