Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use java to handle the function of characters

Shulou Source: shulou.com Published: 2022-06-03 05:17:23 09月22日 Update

This article introduces the knowledge of "how to use java to deal with the function of characters". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. GetBytes is a standard function for java string processing, and its function is to represent the characters represented by the charset encoded string in bytes.

Note: strings are always stored in unicode encoding in java memory.

2. NewString combines and identifies the byte array according to charset coding and converts it to unicode storage.

3. SetCharacterEncoding ()

This function is used to set the http request or the corresponding encoding.

Example

Package com.test.bs; import java.io.UnsupportedEncodingException; public class UnicodeTest2 {public static void main (String [] args) {String a = ""; try {byte [] gb2312 = a.getBytes ("GB2312"); byte [] utf = a.getBytes ("UTF-8"); for (int I = 0; I < gb2312.length; ionization +) {System.out.print (gb2312 [I]);} System.out.println (); for (int I = 0; I < utf.length) ITunes +) {System.out.print (UTF [I]);} System.out.println (); System.out.println (new String (gb2312)); System.out.println (new String (utf)); System.out.println (System.getProperty ("file.encoding")); / / current file encoding method System.out.println (new String (utf, "UTF-8")); System.out.println (new String (gb2312, "UTF-8")) } catch (UnsupportedEncodingException e) {e.printStackTrace ();} "the function of how to use java to handle characters" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Character coding function processing string UTF-8 content byte more knowledge storage utility learning next function memory dilemma instance actual form Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info Linux OPPO Reno Xiaomi