battle programminga forum for elite programmerswith extreme will powerto sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Share | 
 

 java convert string to unicode

Go down 
AuthorMessage
Admin
Admin
avatar

Posts : 120
Join date : 2011-08-01

PostSubject: java convert string to unicode   Sun Mar 25, 2018 8:22 pm



main "
Code:
import java.util.Scanner;

public class xc {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      Scanner s1 = new Scanner(System.in);
      System.out.println("enter input");
      String input = s1.nextLine();
      //char [] chars = { '1', 'a', '\u0152'};
      char [] chars = input.toCharArray();
      String result = "";
      for( int i = 0; i < chars.length; i++) {
          System.out.printf(" char = %c  codepoint = \\u%04x \n", chars[i], Character.codePointAt(chars, i));
         result += ("\\u" + Integer.toHexString(chars[i] | 0x10000).substring(1) );
   }
      System.out.println(result);
}
}

_________________
kurayami no kagi  _____    
Back to top Go down
View user profile http://yotamarker.forumotion.com
Admin
Admin
avatar

Posts : 120
Join date : 2011-08-01

PostSubject: java decode unicode string message to regular string   Sun Mar 25, 2018 8:40 pm

decode :
Code:
import java.io.UnsupportedEncodingException;
import java.util.Scanner;


public class xc {

   public static void main(String[] args) throws UnsupportedEncodingException {
      // TODO Auto-generated method stub
      //Scanner s1 = new Scanner(System.in);
      //System.out.println("enter input");
      //String b = "\u006d\u006f\u0074\u0069\u0020\u0062\u0061\u0072\u0073\u006b\u0069";//s1.nextLine();
      
      String string = "\u006d\u006f\u0074\u0069\u0020\u0062\u0061\u0072\u0073\u006b\u0069";
       byte[] utf8 = string.getBytes("UTF-8");
      
       string = new String(utf8, "UTF-8");
       System.out.println(string);

    }

   }
elephant

_________________
kurayami no kagi  _____    
Back to top Go down
View user profile http://yotamarker.forumotion.com
 
java convert string to unicode
Back to top 
Page 1 of 1
 Similar topics
-
» Convert string (with decimal or a point) to a integer.
» Verify command when used with Java,JUNIT and Eclipse
» selenium RC
» opera browser not loading the page using selenium Rc(Java)
» String comparison using Selenium Ide

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: