# [.net] How to detect "\n" character in a line in a textBox?

This topic is 3657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am developing a text comparer application. How to detect if there is an empty line in the textBox? I have tried with the method String::IsNullOrEmpty and detect if the line is equal to "\n" but it still don't work.. How to do that? I am using Visual C++ and .Net 2.0. Thank you very much.

##### Share on other sites
If the textbox is multiline you could get the lines (with the Lines property) and cicle over them to find a string with 0 lenght (I think that the textbox automatically removes the \n at the end of each line):
            TextBox box = new TextBox();            box.Text = "This is a \n multiline textbox\n\nwith an empty string?";            box.Multiline = true;            Console.WriteLine(box.Lines.Length);            foreach(String s in box.Lines)            {                if (s.Length == 0) Console.WriteLine("found");            }

This seems to work.

##### Share on other sites
Ok, then I will try yours. I have tried to check it out with String::IsNullOrEmpty or is it equal to "\n" or not.

And also if I have found that empty line, I want to highlight it as a empty line so the highlight contains nothing but a single line from left edge to right edge. And also if the line contains any character, I only can select from the first character to the last character only, not full line.

How to do full line selection like that?

Thank you very much..

##### Share on other sites
I don't know if there is an easy way to do that. I would override the Paint method and draw the selected line myself as a rectangle at the specified position. Getting the correct position could become a bit tricky perhaps, but should be doable.

##### Share on other sites
Is it possible to do that? How to do that? Have you ever do it?
If yes, please tell me how..

Thank you very much.

##### Share on other sites
No, I never did it, but you can try by overriding the Paint method and using the Graphic object it provides. Try drawing something (like a circle or something like this) using this object and the drawing methods it offers. If you can do that, then you may try drawing a coloured rectangle where there is the blank line. You will have to take into account font size, window size and scroll position and honestly I don't really know how you should take all this into account.
Start by drawing some shapes on the graphic object, perhaps this will be of inspiration for you :-)