while循环为索引存在

时间:2012-05-26 22:59:47

标签: c# while-loop indexof

我怎么能写一个说明以下(伪代码)的while循环:

While the index of "blahblah" in string 1 exists

do this

2 个答案:

答案 0 :(得分:3)

while(string1.Contains("blahblah")) {
    // do this
}

伪代码编译成C#成功。 0错误,0警告。所用时间:0:00:01.860。

答案 1 :(得分:0)

  var string1 = "blahblah blahblah blahblah blahblah ";
  int pos = -1;
  while (0 >= (pos = string1.IndexOf("blahblah", pos + 1)))
  {
     // do this.
  }