I know it's a simple question but can someone help me figure out how to convert this while loop to a for loop. I keep getting an error trying to convert it
static string CountLines(string s)
{
long count = 0;
int start = 0;
while ((start = s.IndexOf('\n', start)) != -1)
{
count++;
start++;
}
return count.ToString();
}
This is the way I tried
for (int start = 0; start !=-1 ; start = s.IndexOf('\n', start)) {
count++;
start++;
}