Search code examples
javaurlencode

Java Convert Unicode String to English String


I am new to java and i have characters like this

"%6D%61%61%20%77%61%72%64%20%6C%6F%20%65%6E%6E%69%20%73%61%72%6C%75%20%68%6F%75%73%65%20%73%69%74%65%20%6B%6F%72%61%6B%75%20%61%70%70%6C%79%20%63%68%65%73%69%6E%61%20%6D%61%27%61%6D%20%65%74%75%76%61%6E%74%69%20%75%70%61%79%6F%67%61%6D%20%6C%65%6B%75%6E%64%61%20%69%6E%64%69%76%69%64%75%61%6C%20%70%6F%79%69%6E%64%69%20%74%72%79%20%63%68%65%79%61%6D%61%6E%74%61%72%61%61%20%76%61%64%69%6C%65%79%61%6D%61%6E%74%61%61%72%61%20%70%6C%65%61%73%65%20%73%65%6E%64%20%6D%65%20%61%6E%73%77%65%72"

When i try to convert them using this tool. i am able to convert to the values as desired.

converted results :

"maa ward lo enni sarlu house site koraku apply chesina ma'am etuvanti upayogam lekunda individual poyindi try cheyamantaraa vadileyamantaara please send me answer"

but how can i do it using programmatically can someone help.

I tried this

String raw = "%6D%61%61%20%77%61%72%64%20%6C%6F%20%65%6E%6E%69%20%73%61%72%6C%75%20%68%6F%75%73%65%20%73%69%74%65%20%6B%6F%72%61%6B%75%20%61%70%70%6C%79%20%63%68%65%73%69%6E%61%20%6D%61%27%61%6D%20%65%74%75%76%61%6E%74%69%20%75%70%61%79%6F%67%61%6D%20%6C%65%6B%75%6E%64%61%20%69%6E%64%69%76%69%64%75%61%6C%20%70%6F%79%69%6E%64%69%20%74%72%79%20%63%68%65%79%61%6D%61%6E%74%61%72%61%61%20%76%61%64%69%6C%65%79%61%6D%61%6E%74%61%61%72%61%20%70%6C%65%61%73%65%20%73%65%6E%64%20%6D%65%20%61%6E%73%77%65%72";
String searchSection = new String(raw.getBytes(StandardCharsets.UTF_8), "UTF-8");
System.out.println( searchSection);

if this question is duplicate of any other question please point me in the right direction thanks

Converted text should match


Solution

  • You can achieve it using URLDecoder.decode(yourMessage, "UTF-8") from java.net:

    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;
    
    public class Main {
        public static void main(String[] args) {
            String yourMessage = "%6D%61%61%20%77%61%72%64%20%6C%6F%20%65%6E%6E%69%20%73%61%72%6C%75%20%68%6F%75%73%65%20%73%69%74%65%20%6B%6F%72%61%6B%75%20%61%70%70%6C%79%20%63%68%65%73%69%6E%61%20%6D%61%27%61%6D%20%65%74%75%76%61%6E%74%69%20%75%70%61%79%6F%67%61%6D%20%6C%65%6B%75%6E%64%61%20%69%6E%64%69%76%69%64%75%61%6C%20%70%6F%79%69%6E%64%69%20%74%72%79%20%63%68%65%79%61%6D%61%6E%74%61%72%61%61%20%76%61%64%69%6C%65%79%61%6D%61%6E%74%61%61%72%61%20%70%6C%65%61%73%65%20%73%65%6E%64%20%6D%65%20%61%6E%73%77%65%72";
    
            try {
                System.out.println( URLDecoder.decode(yourMessage, "UTF-8"));
            } catch (UnsupportedEncodingException uee) { }
    
        }
    }
    

    Output:

    maa ward lo enni sarlu house site koraku apply chesina ma'am etuvanti upayogam lekunda individual poyindi try cheyamantaraa vadileyamantaara please send me answer