Use Java to implement the native2asscii command

Source: Internet
Author: User
  1. Package com. Work. util;
  2. Import java. Io. unsupportedencodingexception;
  3. /**
  4. * It is ready to be used when Javascript is dynamically generated.
  5. * @ Author wangmingjie
  6. *
  7. * JAVA Implementation of the native2ascii command!
  8. *
  9. */
  10. Public class native2ascii {
  11. /**
  12. * GBK can be converted into UTF-8 Encoding
  13. * @ Param Str
  14. * @ Return
  15. */
  16. Public static string native2ascii (string Str ){
  17. Char [] AC = Str. tochararray ();
  18. Stringbuffer rs = new stringbuffer (AC. Length );
  19. For (int K = 0; k <AC. length; k ++)
  20. If (AC [k]> '/123 '){
  21. Rs. append (char) 92 );
  22. Rs. append (char) 117 );
  23. String S1 = integer. tohexstring (AC [k]);
  24. Stringbuffer = new stringbuffer (S1 );
  25. Stringbuffer. Reverse ();
  26. Int L = 4-stringbuffer. Length ();
  27. For (INT I1 = 0; I1 <L; I1 ++)
  28. Stringbuffer. append ('0 ');
  29. For (INT J1 = 0; J1 <4; J1 ++)
  30. Rs. append (stringbuffer. charat (3-J1 ));
  31. } Else {
  32. Rs. append (AC [k]);
  33. }
  34. Return Rs. tostring ();
  35. }
  36. Public static void main (string [] ARGs) throws unsupportedencodingexception {
  37. System. Out. println (native2ascii. native2ascii ("We are Chinese "));
  38. System. Out. println ("/u6211/u4eec/u662f/u4e2d/u56fd/u4eba ");
  39. System. Out. println (native2ascii. native2ascii ("integrity check. RaQ "));
  40. System. Out. println (java.net. urlencoder. encode ("integrity check. RaQ", "GBK "));
  41. System. out. println (java.net. urldecoder. decode ("% Cd % EA % D5 % FB % D0 % D4 % BC % EC % B2 % e9.raq", "GBK "));
  42. System. Out. println (java.net. urlencoder. encode ("China", "GBK "));
  43. }
  44. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.