what is string loop
Answers
Answer:
C# program that uses string for-loop
using System;
class Program
{
static void Main()
{
string input = "Dot Net Perls website";
//
// Check each character in the string using for-loop.
//
int spaces1 = 0;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == ' ')
{
spaces1++;
}
}
//
// BAD: Check each character in the string with ToString calls.
//
int spaces2 = 0;
for (int i = 0; i < input.Length; i++)
{
if (input[i].ToString() == " ") // NO
{
spaces2++;
}
}
//
// Write results.
//
Console.WriteLine(spaces1);
Console.WriteLine(spaces2);