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

  • Home
  • SEARCH
  • 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 9216737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:28:51+00:00 2026-06-18T02:28:51+00:00

I am using Jre 1.6. I am executing the following lines of code: String

  • 0

I am using Jre 1.6.
I am executing the following lines of code:

String unicodeValue = “\u001B”; text = text.replaceAll(“” + character, unicodeValue);

Here, text is a string object containing an invalid XML character of Unicode value ‘\u001B’.
So, I am converting the invalid XML character to its Unicode value to write in the XML.

But on doing text.replaceAll, the ‘\’ is getting stripped and the character is replaced by ‘u001B’.

Can anyone please suggest a way to retain the ‘\’ after replacing the character with its unicode value ?

  • 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-18T02:28:52+00:00Added an answer on June 18, 2026 at 2:28 am

    The problem is that str.replaceAll(regex, repl) is defined as returning the same as

    Pattern.compile(regex).matcher(str).replaceAll(repl)
    

    But the documentation for replaceAll says,

    Note that backslashes () and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.

    So this means we need to add several extra layers of escaping:

    public class Foo {
    
        public static void main(String[] args)
        {
            String unicodeValue = "\u001B";
            String escapedUnicodevalue = "\\\\u001B";
            String text = "invalid" + unicodeValue + "string";
    
            text = text.replaceAll(unicodeValue, escapedUnicodevalue);
    
            System.out.println(text);
        }
    }
    

    prints invalid\u001Bstring as desired.

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

Sidebar

Related Questions

I'm using enumerations to replace String constants in my java app (JRE 1.5). Is
Using the stock Sun 1.6 compiler and JRE/JIT, is it a good idea to
Using import datetime in python, is it possible to take a formatted time/date string
Using JRE 5.0.0, simulator device is an 8520. On a screen I am using
I have the following really simple code for creating a JLabel and adding it
I am relying on the default JAXP implementation and using the Oracle JRE .
For an java web application, I got this error when using JRE 1.6.0_22 java.lang.SecurityException:
By using the JRE or some other runtime environment, is it possible to compile
I am having issues trying to get a database connection using the code below:
I developed an application using the JRE 7.0.0. In the simulator the app works

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.