using System;
namespace 字符串比较算法
{
class Program
{
static void Main(string[] args)
{
string s1 = "abcdafghafgmjklmn";
string s2 = "afgm";
int S1Index = 0;
int S2Index = 0;
int Index=0;
while ((S1Index < s1.Length) && S2Index < s2.Length)//比较
{
if (s1[S1Index] == s2[S2Index])
{
S1Index++;
S2Index++;
}
else
{
S1Index -= S2Index - 1;
S2Index = 0;
}
if (S2Index == s2.Length)
{
Index = S1Index-s2.Length;
}
}
if (Index == 0)
{
Console.WriteLine("字符串不存在!");
}
else
{
Console.WriteLine("Index={0}", Index);
}
Console.ReadLine();
}
}
}
单步一下,you can get more!
字符串比较算法
最新推荐文章于 2022-05-31 16:56:56 发布