while 循环表示存在的索引

本文关键字:索引 存在 表示 循环 while | 更新日期: 2023-09-27 18:35:30

我怎么能写一个while循环来表达以下内容(伪代码):

While the index of "blahblah" in string 1 exists
do this

while 循环表示存在的索引

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

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

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