本文介绍了如何检查字符串c#中的重复字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个检查字符串中重复字母的程序。
I am creating a program that checks repeated letters in a string.
例如:
这是我的代码:
string repeatedWord = "woooooooow";
for (int i = 0; i < repeatedWord.Count(); i++)
{
if (repeatedWord[i] == repeatedWord[i+1])
{
// ....
}
}
代码有效,但总是会出错,因为最后一个字符 [i + 1]
为空/ null。
The code works but it will always have an error because the last character [i + 1]
is empty/null.
错误是索引超出了数组的范围。
任何解决方案?
推荐答案
运行循环直到 repeatedWord.Count() - 1
这篇关于如何检查字符串c#中的重复字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!