【发布时间】:2012-05-26 22:59:47
【问题描述】:
我怎样才能写出如下语句(伪代码)的 while 循环:
While the index of "blahblah" in string 1 exists
do this
【问题讨论】:
-
你的伪代码几乎是真正的 C#。为什么不自己学习如何用 C# 编写它呢?
标签: c# while-loop indexof
我怎样才能写出如下语句(伪代码)的 while 循环:
While the index of "blahblah" in string 1 exists
do this
【问题讨论】:
标签: c# while-loop indexof
while(string1.Contains("blahblah")) {
// do this
}
成功编译为 C# 的伪代码。 0 个错误,0 个警告。所用时间:0:00:01.860。
【讨论】:
if(string1.Contains("blahblah")) while(true){ DoThis();} 非常相似,并且永远循环......
string1 是从DoThis() 修改的,则不会。
var string1 = "blahblah blahblah blahblah blahblah ";
int pos = -1;
while (0 >= (pos = string1.IndexOf("blahblah", pos + 1)))
{
// do this.
}
【讨论】: