How would you interpret if I ask you to count number of rows in TextBox

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I have an empty TextBox from the beginning. Assume now if I write abc and
then hit the CR button three times
how many rows would you say that I have in the TextBox.

So If I want to count the number of rows according to a reasonable
interpretation can I then just count the number of CR which is ASCII 13.

//Tony
 
Tony Johansson skrev:
Hello!

I have an empty TextBox from the beginning. Assume now if I write abc and
then hit the CR button three times
how many rows would you say that I have in the TextBox.

So If I want to count the number of rows according to a reasonable
interpretation can I then just count the number of CR which is ASCII 13.

You could, but you need some more advanced code if you want to calculate
the size because a singe "line" may wrap over several lines if the text
box is too narrow.
 
Tony Johansson said:
Hello!

I have an empty TextBox from the beginning. Assume now if I write abc and
then hit the CR button three times
how many rows would you say that I have in the TextBox.

So If I want to count the number of rows according to a reasonable
interpretation can I then just count the number of CR which is ASCII 13.

//Tony


You are off by one. I don't think that gives the correct number, as if you
only have a single line of text, there would be "zero" CRs. The logic
should be similar to this, which says 4:

static void Main(string[] args)
{
string s = "abc\n\n\n";
string[] lines = s.Split(new char[] { '\n' });
Console.WriteLine(lines.Count());
Console.ReadLine();
}
 
Hello!

I have an empty TextBox from the beginning. Assume now if I write abc and
then hit the CR button three times
how many rows would you say that I have in the TextBox.

So If I want to count the number of rows according to a reasonable
interpretation can I then just count the number of CR which is ASCII 13.

//Tony

The TextBox has a Lines property which is a string array. Just check
the length of that array to get the number of lines.

Chris
 
Back
Top