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

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
 
B

Bjørn Brox

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.
 
F

Family Tree Mike

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();
}
 
D

dunawayc

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top