Thursday, 8 August 2013

How to check repeated letters in a string c#

How to check repeated letters in a string c#

I am creating a program that checks repeated letters in a string.
for example:
wooooooooooow happpppppppy
this is my code:
string repeatedWord = "woooooooow";
for (int i = 0; i < repeatedWord.Count(); i++)
{
if (repeatedWord[i] == repeatedWord[i+1])
{
....
}
}
The code works but it will always have an error because the last character
[i+1] is empty/null.
The error is Index was outside the bounds of the array. any solution for
this?

No comments:

Post a Comment