Hi, this something very basic I know it, but how can I skip the spaces in this basic program please.
string Palabras = string.Empty;
//int ContEspacios;
Console.WriteLine("Escribe una palabra:");
Palabras = Console.ReadLine();
foreach (var X in Palabras.Length.ToString())
{
Console.WriteLine("Cuantas palabras tiene {0}:",X);
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Loading

VulpesPosted Apr 10, 2013, 10:49 AM
Try the following:
Freddy AbreuPosted Apr 10, 2013, 12:05 PM
Blessings.
VulpesPosted Apr 10, 2013, 11:35 AM
if (s == 32)
then the char 's' is converted to its Unicode equvalent before making the comparison.
The reason why Sandeep's code is shorter than mine is because mine deals with the possibility that there could be multiple consecutive spaces between words.
Freddy AbreuPosted Apr 10, 2013, 11:20 AM
you mean 32 bits? right?
Forgive me for the ignorant question.
Freddy AbreuPosted Apr 10, 2013, 11:14 AM
This is the best forum I've ever been before.
Sandeep Singh ShekhawatPosted Apr 10, 2013, 11:00 AM
//int ContEspacios;
Console.WriteLine("Escribe una palabra:");
Palabras = Console.ReadLine();
int ContEspacios = 0;
foreach (char s in Palabras)
{
if (s == 32)
{
ContEspacios++;
}
}
Console.WriteLine("Total Number of words : {0}", ++ContEspacios);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);