Program ma wyświetlić ilość wierszy oraz ilość znaków w każdym wierszu.
class Program
{
static void Main(string[] args)
{
string tekst = "Now, fair Hippolyta, our nuptial hour\n" +
"Draws on apace; four happy days bring in\n" +
"Another moon: but, O, methinks, how slow\n" +
"This old moon wanes! she lingers my desires,\n" +
"Like to a step-dame or a dowager\n" +
"Long withering out a young man revenue.";
int verseCounter = 0;
int letterCounter = 0;
int position = 0;
while ((position = tekst.IndexOf('\n', position + 1)) >= 0)
{
verseCounter++;
}
foreach (char letter in tekst)
{
if (letter != ' ')
{
letterCounter++;
}
}
Console.Write(tekst + "\n" + "tekst ma {0} ", verseCounter+1 + " linii\n");
Console.WriteLine("Ilość znaków : {0}",letterCounter);
Wiersze liczy i na tą chwile zrobiłem tylko, żeby zliczał wszystkie znaki. Jak można to najprościej przerobić, żeby liczył znaki w wierszu.