Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net String.Length counting return as 2 chars?

Tags:

string

c#

asp.net

Im counting characters of a message from a textbox that will be sent as an sms, I've noticed that txtBody.Text.Length is counting more characters for returns, understand i want to keep the formatting of a newline but .net is counting 2 characters for this is there any way to keep the new line but get the counter to be accurate or is a return itself 2 characters ???

like image 204
Ryan86 Avatar asked Aug 31 '26 20:08

Ryan86


1 Answers

The newline in windows is indeed 2 characters - CrLf - ASCII 13 followed by ASCII 10.

You can simply decrement 2 from the returned Length, or get a count of all Environment.NewLine, double that by 2 and decrement from the Length.

like image 109
Oded Avatar answered Sep 02 '26 11:09

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!