C# Count All Occurences Of Line Feed and Carrage Return

Someone asked on Stack Overflow:

In C# i am making a simple text editor with line numbers. I want to count the ammount of valid line breaks in a string.

i want to count

\r \n \r\n

How can i do this?

Or better yet, can someone point me to an article on how to line number an rtf box

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

Counting Lines - http://ryanfarley.com/blog/archive/2004/04/07/511.aspx

RTB With Line Numbers - http://www.xtremedotnettalk.com/showthread.php?s=&threadid=49661&highlight=RichTextBox


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.