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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:54:46+00:00 2026-05-25T00:54:46+00:00

Having a hard time replacing a quote with an escaped quote. I have a

  • 0

Having a hard time replacing a quote with an escaped quote. I have a string that has the value of ‘Foo “bar” foobar’, and I am trying to replace the quotes around bar with escaped quotes, and it isn’t working. I am going crazy.

s=s.replaceAll("\"","\\\"");

I would expect s to have the value of ‘foo \”bar\” foobar’, but it doesn’t. Any help?

  • 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-25T00:54:47+00:00Added an answer on May 25, 2026 at 12:54 am

    replaceAll uses regular expressions – in which the backslash just escapes the next character, even in the replacement.

    Use replace instead and it’s fine… or you can double the backslash in the second argument if you want to use the regular expression form:

    String after = before.replaceAll("\"", "\\\\\"");
    

    This could be useful if you need to match the input using regular expressions, but I’d strongly recommend using the non-regex form unless you actually need regex behaviour.

    Personally I think it was a mistake for methods in String to use regular expressions to start with – things like foo.split(".") which will split on every character rather than on periods, completely unexpectedly to the unwary developer.

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

Sidebar

Related Questions

I'm having hard time trying to set certain cell's value in table. Here is
I seem to have hit an error message that I'm having a hard time
I'm having hard time trying to figure out how to auto-save user data in
Having a hard time figuring out the best way to do this... I have
I've been having a hard time trying to understand PyPy's translation. It looks like
I'm having a hard time determining what characters must be escaped when using Perl's
i'm having hard time trying to understand how interrupts work. the code below initialize
I'm having hard time getting this snippet to work. I have made a minimal
I having hard time understanding importance and benefits of Annotations and so have two
i am having hard time to fix my problem on VirtualStringTree. I have NodeData

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.