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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:25:50+00:00 2026-06-15T17:25:50+00:00

I want to escape escape sequences in a string. Example: if I had a

  • 0

I want to escape escape sequences in a string.

Example: if I had a string whose contents were “\n\u0073”, I need to escape them in such a way that if I printed it to the command line, I would see

this:
\n\u0073
instead of:

s

I’ll also be escaping double quotes (“) and backslashes (\), and I figured out an expression to escape those already:

Pattern p = Pattern.compile("([\"\\\\])");
String str = p.matcher("\"\n\u0073\\"").replaceAll("\\\\$1");

This yields me:

\"
s\\

It doesn’t take care of the escape sequences, though. What I want is:

\"\n\u0073\\

What modifications do I need to make to escape the escape sequences?

  • 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-15T17:25:51+00:00Added an answer on June 15, 2026 at 5:25 pm

    You may use the StringEscapeUtils. There is method escapeJava() on it. Unfortunately, imo, there is no way to escape unicode literals like \u0073 so for your example input “\”\n\u0073\””, StringEscapeUtils.escapeJava("\"\n\u0073\"") will return \"\ns\"

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

Sidebar

Related Questions

i want that during marshelling special character should escape, is there any way to
I have a bunch of string with special escape codes that I want to
I'm looking for a way to convert a string that contains a character escape
I want to replace and insert escape character sequences with their escape character values,
Using XSLT and XPath 1.0, I have a string I want to escape for
How do I build an escape sequence string in hexadecimal notation. Example: string s
The strings I want to match includes some escape sequences, like 'It\'s something'. It's
I want to remove all types of escape sequences from a list of strings.
That is, I want to build a quoted string on the fly that contains
Possible Duplicate: Process escape sequences in a string in Python If I get this

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.