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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:54:52+00:00 2026-05-20T01:54:52+00:00

Why does .Replace(Environment.NewLine, <br />) give this result: asdasd<br />waahahahaha<br />asdadsa<br />multiline<br /><br /><br

  • 0

Why does .Replace(Environment.NewLine, "<br />") give this result:

asdasd<br />waahahahaha<br />asdadsa<br />multiline<br /><br /><br />asdad
  • 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-20T01:54:53+00:00Added an answer on May 20, 2026 at 1:54 am

    Probably because there are more than one new line between “multiline” and “asdad”.

    Example

    var someText = string.Format("First line{0}Second line{0}Multiple line breaks{0}{0}{0}some text", Environment.NewLine);
    
    var html = someText.Replace(Environment.NewLine, "<br />");
    

    html will now look like this:

    First line<br />Second line<br/>Multiple line breaks<br /><br /><br />some text
    

    Edit

    In your case your web page will display the <br /> in the web-browser and not create a new line because it encodes the html output.

    What you will need to do is use HtmlString, try this:

    <div class="display-field">
        <%: new HtmlString(Model.Body.Replace(Environment.NewLine, "<br />")) %>
    </div>
    

    Also see this thread here on StackOverflow talking about “ASP.NET MVC Razor – output HTML string non escaped”.

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

Sidebar

Related Questions

foo\r\nbar.replace(/(foo).+/m, bar) Hello. I can not understand why this code does not replace foo
why does the following js expression: test1 foo bar test2.replace(/foo.bar/, $') result in the
I have a simple script that does some search and replace. This is basically
I essentially want to do this: if(obj is IDictionary) { return { + string.Join(Environment.NewLine,
The pattern in this code does not replace the parenthesis. I've also tried /(|)/g.
I'm confused as to what this regex does: preg_replace('/^\s*\((.+)\)\s*$/', '$1', $part); Can someone give
I have a regex as such eregi_replace(s=.*&,,$section->urlToThreads); What it does is replace everything with
Does anyone nows how to replace null values with another column in another table
Does anyone know why why?? <abc> and <a b c> and <a b>.replace( /<([^>]+)>/g,
I have a ColdFusion script that does: <cfset content = replace(content,&##147;,,all)> Which replaces &147;

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.