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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:56:37+00:00 2026-05-14T14:56:37+00:00

I’m writing a utility that takes in a .resx file and creates a javascript

  • 0

I’m writing a utility that takes in a .resx file and creates a javascript object containing properties for all the name/value pairs in the .resx file. This is all well and good, until one of the values in the .resx is

This dealer accepts electronic orders.

/r/nClick to order {0} from this dealer.

I’m adding the name/value pairs to the js object like this:

streamWriter.Write(string.Format("\n{0} : \"{1}\"", kvp.Key, kvp.Value));

When kvp.Value = “This dealer accepts electronic orders./r/nClick to order {0} from this dealer.”

This causes StreamWriter.Write() to actually place a newline in between ‘orders.’ and ‘Click’, which naturally screws up my javascript output.

I’ve tried different things with @ and without using string.Format, but I’ve had no luck. Any suggestions?

Edit: This application is run during build to get some javascript files deployed later, so at no point is it accessible to / run by anyone but the app developers. So while I obviously need a way to escape characters here, XSS as such is not really a concern.

  • 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-14T14:56:38+00:00Added an answer on May 14, 2026 at 2:56 pm

    Your problem has already happened by the time you get to this code. String.Format will not “expand” literal \n and \r in the substituted strings ({0} etc) into newline and CR, so it must have happened at some earlier point, possibly while reading the .resx file.

    You have two possible solutions. One, as you discovered in the comments to DonaldRay’s answer, is to explicitly reverse this replacement, and replace literal newlines with the two characters \n:

    kvp.Value.Replace("\r",      // <-- replaced by the C# compiler with a literal CR character
                      "\\r");    // <-- "\\" replaced by the C# compiler with a single "\",
                                 // leaving the two-char string "\r"
    

    You will need to do the same for every character that could appear in your strings. \n and \r are the most common, and then \t (tab); that’s probably enough for most dev tools.

    string formatted = kvp.Value.Replace("\r", "\\r")
                                .Replace("\n", "\\n")
                                .Replace("\t", "\\t");
    

    Alternatively, you could look upstream at the .resx file reading code, and try to find and remove the part that’s explicitly expanding these character sequences. This would be a better general solution, if it’s possible.

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

Sidebar

Ask A Question

Stats

  • Questions 398k
  • Answers 398k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to create a new GdkPixbufLoader and pass the… May 15, 2026 at 3:37 am
  • Editorial Team
    Editorial Team added an answer No. There is no way of knowing which object it… May 15, 2026 at 3:37 am
  • Editorial Team
    Editorial Team added an answer Check your simulated user interface components in IB. You probably… May 15, 2026 at 3:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.