public static void Main()
{
int i=0;
string[] a=new string[50];
string[] b=new string[50];
Console.WriteLine("please input a;");
Console.ReadLine();
Console.WriteLine("please input b:");
Console.ReadLine();
Class6 myClass6=new Class6();
myClass6.index_pl(a,b,i);
Console.WriteLine("a={0},b={1}",a,b);
}

public int index_pl(string S,string T,int pos)
{
int i=0;
    char Slength=S[0];
char Tlength=T[0];
i=pos;
char PatStartChar=T[1];
char PatEndChar=T[Tlength];
while(S[i]<=Slength-Tlength+1)
{
if(S[i]!=PatStartChar)
{
++i;
}
else if(S[i+Tlength-1]!=PatEndChar)
{
++i;
}
else
{
   int k=1,j=2;
while((j<Tlength)&(S[i+k]=T[j]))
{
    ++k;
++j;
}
if(j==Tlength)
{
return i;
}
else 
{
  ++i;
} }
return 0;
}
}
c:\inetpub\wwwroot\c\Class6.cs(47): 运算符“&”无法应用于“bool”和“char”类型的操作数
c:\inetpub\wwwroot\c\Class6.cs(47): 无法对属性或索引器“string.this[int]”赋值 -- 它是只读的
代码为: while((j<Tlength)&(S[i+k]=T[j]))
index_pl为串的首尾匹配算法。谢谢

解决方案 »

  1.   

    while((j<Tlength)&&(S[i+k]=T[j]))
    & --> &&
      

  2.   

    比较使用:<   <=  ==  >  =>逻辑关系使用: 并列 && 或  ||
      

  3.   

    更正while((j<Tlength)&&(S[i+k]==T[j]))
    & --> &&
    = --> ==
      

  4.   

    c:\inetpub\wwwroot\c\Class6.cs(22): 与“c.Class6.index_pl(string, string, int)”最匹配的重载方法具有一些无效参数c:\inetpub\wwwroot\c\Class6.cs(22): 参数“2” : 无法从“string[]”转换为“string”myClass6.index_pl(a,b,i);
      

  5.   

    如果定一个初始字符串,并给它长度,定义应该如下:
    string strBuffer = new string(50);
      

  6.   

    sorry!string strBuffer = new string( (char)0, 50 );
      

  7.   

    S[i+k]=T[j]是赋值,其的结果为char而非bool自然无法与bool比较