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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:17:31+00:00 2026-05-28T00:17:31+00:00

I’m looking for a way to convert a string that contains a character escape

  • 0

I’m looking for a way to convert a string that contains a character escape sequence into the represented character.

So, for instance, I want to parse the string \" (which has two characters, a backslash and a double-quote) into the char ". So, an array of chars into one char.

So something that might do something like this and vice versa:

package test;
public class Test {
    private static char parseChar(String string) {
        char c = 0;
        if ("\\n".equals(string)) {
            c = '\n';
        }else if ("\\t".equals(string)) {
            c = '\t';
        }else if ("\\r".equals(string)) {
            c = '\r';
        }else if ("\\f".equals(string)) {
            c = '\f';
        }else if ("\\b".equals(string)) {
            c = '\b';
        }else if ("\\\'".equals(string)) {
            c = '\'';
        }else if ("\\\"".equals(string)) {
            c = '\"';
        }else if ("\\\\".equals(string)) {
            c = '\\';
        }
        return c;
    }
    public static void main(String[] args) {
        for (String arg : args) {
            System.out.println(arg + " : " + (int)parseChar(arg) + " : " + parseChar(arg) + ";");
        }
    }
}

I could not believe there is nothing in java.lang or other that can provide me with good (maybe native) code for this because I feel the above code might be incomplete and not parse every problematic (escapable?) character, because well I’m a noob.
I want a tool that can do the same thing as the String constructor :

String st = "\"";
char ch = st.charAt(0);

ch output : “;

Thank you for reading this, I am sorry if not clear I will check regularly and correct if asked.

PS:

When I run the above code:

java -classpath ~/workspace/MacroRecorder/bin/ test.Test \\n \\t \\f \\r \\b \\\’ \\\” \\\\;

…it outputs

\n : 10 : 
;
\t : 9 :    ;
\f : 12 : 
          ;
;r : 13 : 
\b : 8 :;
\' : 39 : ';
\" : 34 : ";
\\ : 92 : \;

But in Eclipse, the output is completely different with the same parameters especially the ” is very messy.

  • 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-28T00:17:31+00:00Added an answer on May 28, 2026 at 12:17 am

    Apache Commons to the rescue with StringEscapeUtils, you want the unescapeJava method I think: http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.html#unescapeJava(java.lang.String)

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string

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.