public static string shita1(string st1)
{
string st2 = "", stemp = st1;
int i;
for(i=0; i<stemp.Length; i++)
{
if (stemp.IndexOf("cbc") == i)
{
i += 2 ;
stemp = "";
stemp = st1.Substring(i);
i = 0;
}
else
st2 = st2 + stemp[i];
}
return st2;
}
static void Main(string[] args)
{
string st1;
Console.WriteLine("enter one string:");
st1 = Console.ReadLine();
Console.WriteLine(shita1(st1));
}
}
我接到了我的大學一challange刪除一組字符,則challange是從字符串中移動任何「CBC」字......使用的indexOf(C#)從字符串
這是我的代碼......當我只使用一個「cbc」時,它可以工作,但是當我使用其中的2個時,它可以幫助... :)
'string result = input.replace(「cbc」,string.Empty);'? –