我希望用户写出他希望的任何字符串(一个单词或整个句子),然后我想要查找每个“in”并将其替换为“ ter“,但在更换之前,应打印每个”in“的位置。c#关于计数单词“in”的建议并将其替换为“ter”
Console.Write("Write some string: ");
string s1 = Console.ReadLine();
s1 = s1.Replace("in", "ter");
Console.WriteLine("After replacement we got new string {0}!", s1);
Console.ReadKey(true);
'IndexOf'是你的朋友。有一个重载需要一个开始索引。使用该重载查找所有事件。 – CodesInChaos 2012-01-10 20:20:28
这是一项家庭作业.. – MethodMan 2012-01-10 20:21:19
IndexOf的文档:http://msdn.microsoft.com/en-us/library/k8b1470s.aspx – 2012-01-10 20:21:48