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 8223365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:40:04+00:00 2026-06-07T14:40:04+00:00

All (this is back-to-basics!), I have a string of information I am pulling from

  • 0

All (this is back-to-basics!), I have a string of information I am pulling from SQL Server. The string is something like

Hello, my name is Frank Butcher\n\n
and I work at Watford Car lot, 
and I am 65 years old.

The message is to be pulled into a message box to provide information on a process. I read the string using

SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = 0;
cmd.CommandText = strSQL;
strResult = cmd.ExecuteScalar().ToString();

this gets the string, but when I put this into my text box the message is displayed with \n\n not with the required double NewLine.

I have tried using

strResult = strResult.Replace("\n", Environment.NewLine);

on the string but this does not help. Am I going mental, what am I doing wrong?

Thanks for your time.

  • 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-06-07T14:40:06+00:00Added an answer on June 7, 2026 at 2:40 pm

    I am assuming you have stored a literal backslash then the character “n” in the string in the database, and not a newline character. Thus you have to do the String.Replace which you are doing.

    You are so close, but you need to escape your backslash:

    strResult = strResult.Replace("\\n", Environment.NewLine);
    

    Without escaping the backslash, the compiler is interpreting the \n to be a special escape sequence for a newline, so your line becomes the equivalent of “replace NewLine with NewLine” (which you have figured out does nothing).

    Alternatively, you can prefix the string constant with an @ symbol, meaning to treat it as a literal:

    strResult = strResult.Replace(@"\n", Environment.NewLine);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I'm pulling back a user's feed. This contains all of that
I have an application that plays back video frame by frame. This is all
hello all this seems to be my problem I have a table in mysql
This has to be a common question that all programmers have from time to
Possible Duplicate: Splitting a string in C++ I have this vector function from one
All the articles I Googled on this subject are dated back in 2004-2005. Basically
Let's say I have some code like this in AS3 for(...) thing = new
This seems like a pretty obvious, basic thing to expect from the Graph API
Hi all this is my xml file with xsd defined as internal to it
How can I get all this to not only output on the screen, but

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.