Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6797923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:40:07+00:00 2026-05-26T18:40:07+00:00

Im counting characters of a message from a textbox that will be sent as

  • 0

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 ???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:40:07+00:00Added an answer on May 26, 2026 at 6:40 pm

    Textbox input will give you Environment.Newline whenever the user has input a new line (barring some relatively strange copy-pasting), which on windows is the same as "\u000D\u000A" (or the shorter "\r\n" which means the same thing).

    For SMS sending you only really need to use U+000A.

    Hence you can simply do msg.Replace("\r\n", "\n") before you do any further work. Not only will you get the Length result you want, but you cut down on wasted characters that SMSs don’t need, and every char counts when it comes to SMS, hnce hrribl nnsens lik dis!

    You might as well normalise further to msg.Replace("\r\n", "\n").Replace('\r', '\n\') to make more sense out of strange copy-pasted data with non-Windows-normal line-breaks (does happen in some scenarios).

    Note that you’re going to have more complications if you can’t stay within the GSM 7-bit alphabet, though if you can’t stay within the 8-bit either, then at least your complications will match between .NET and SMS; since .NET uses UTF-16 and SMS does when other encodings don’t suffice, they treat surrogates the same as far as length goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ignore counting the length of characters in the text if there
I believe (from some research reading) that counting down in for-loops is actually more
The problem reduces to counting \n characters, so is there a function that can
I am counting words in a text field and after a certain amount of
I have some dynamic text contained in a div that is set to whatever
I'm a python programmer getting to learn C from the K&R book. This will
I found a jquery snippet of code for counting down the characters when you
Scenario: I have a text file that has pipe (as in the | character)
I count characters using NobleCount and the following code: $('#message').NobleCount('#messageInfo',{ max_chars: getMaxChars(), on_negative: function(t_obj,
Is there any plugin for jquery that counts the length of entered word...no matter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.