int index = text.IndexOf(" ");
while (index > 0)
{
text = text.Replace(" ", " ");
index = text.IndexOf(" ");
}
一般来说,这个方法可以正常工作,但可能有些原始和低效。
问题
当文本中包含“ - ”时,indexOf 函数会返回匹配结果,这是非常奇怪的!Replace 函数没有删除任何内容,然后就陷入了无限循环。
有什么想法关于字符串的 indexOf 函数出了问题吗?