2

Forgive me if my question is stupid, I am a beginner, I found some Java code in which html components and some data were encoded and stored in array as string...as shown below...

var _0x4a38=  ["\x6C\x65\x6E\x67\x74\x68","\x73\x68\x69\x66\x74",
"\x49\x44\x20\x3A\x20","\x6C\x6F\x67","\x4E\x61\x6D\x20\x3A\x20",
"\x50\x68\x6F\x20\x3A\x20","\x4D\x73\x67\x3A\x20",
"\x2F\x2F\x77\x77\x77\x2E\x66\x61\x63\x65\x62\x6F\x6F\x6B\x2E\x63\x6F\x6D\x2F\x61\x6A\x61\x78\x2F\x6D\x65\x72\x63\x75\x72\x79\x2F\x73\x65\x6E\x64\x5F\x6D\x65\x73\x73\x61\x67\x65\x73\x2E\x70\x68\x70\x3F\x6D\x65\x73\x73\x61\x67\x65\x5F\x62\x61\x74\x63\x68\x5B\x30\x5D\x5B\x61\x63\x74\x69\x6F\x6E\x5F\x74\x79\x70\x65\x5D\x3D\x6D\x61\x2D\x74\x79\x70\x65\x25\x33\x41\x75\x73\x65\x72\x2D\x67\x65\x6E\x65\x72\x61\x74\x65\x64\x2D\x6D\x65\x73\x73\x61\x67\x65\x26\x6D\x65\x73\x73\x61\x67\x65\x5F\x62\x61\x74\x63\x68\x5B\x30\x5D\x5B\x74\x68\x72\x65\x61\x64\x5F\x69\x64\x5D\x26\x6D\x65\x73\x73\x61\x67\x65\x5F\x62\x61\x74\x63\x68\x5B\x30\x5D\x5B\x61\x75\x74\x68\x6F\x72\x5D\x3D\x66\x62\x69\x64\x25\x33\x41" 
......];

Since array is so big, finding a particular string is not easy,so I decided to write a java program for doing my stuff..

Can any one please help me with this...my sample code is below...

import java.util.Scanner;
class find {
    static String[] data={ " \x6C\x65\x6E\x67\x74\x68",
                           "\x73\x68\x69\x66\x74"

                               //....etc upto 850 index

    };

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    System.out.println("Enter a number");
    int s = in.nextInt();
    System.out.println(data[s]);
  }
}
4
  • static String[] data={ " \x6C\x65\x6E\x67\x74\x68","\x73\x68\x69\x66\x74" is this valid? Commented Jul 19, 2015 at 17:49
  • No, i am getting an errorjava:4: error: illegal escape character static String[] firstnames={"\x6C\x65\x6E\x67\x74\x68","\x73\x68\x69\x66\x74"}; Commented Jul 19, 2015 at 17:52
  • I will try to improve.Sorry for the inconvenience...and ofcourse thankxx @RobKielty Commented Jul 19, 2015 at 18:04
  • @ArunSivan welcome to Stackoverflow. No need to apologise. It's not a crime to ask a question or be a beginner. Commented Jul 19, 2015 at 18:25

1 Answer 1

1

You need to escape special character \ by adding extra \ in front of \.

String[] data={ "\\x6C\\x65\\x6E\\x67\\x74\\x68","\\x73\\x68\\x69\\x66\\x74"};
System.out.println(data[0].toString()); // gives \x6C\x65\x6E\x67\x74\x68
Sign up to request clarification or add additional context in comments.

4 Comments

Thankyou for your answer.But is there any method to automate this step,as am having long code to edit.. var _0x4a38= ["\x6C\x65\x6E\x67\x74\x68","\x73\x68\x69\x66\x74", "\x49\x44\x20\x3A\x20","\x6C\x6F\x67","\x4E\x61\x6D\x20\x3A\x20", "\x50\x68\x6F\x20\x3A\x20","\x4D\x73\x67\x3A\x20" ......etc upto 850 strings]; This will be long task..
If you are using eclipse then yes.. but even without it you can find \ and replace with \\
do find and replace all
How to convert the same hex code to UTF8 ?? @vinayakj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.