This article briefly introduces the code for converting the unicode entity encoding of html by using corner stone. When developing a browser using corner stone, we need to convert the unicode entity encoding of html to display it normally.
How to convert the unicode entity encoding in html by using corner stone
During the development of the j2's browser, we need to convert the unicode entity encoding of html for normal display. See the following code:
- <Ahrefahref = "http://wap.monternet.com/"> back to mxnet </a> <br/>
-
The method is as follows:
- PrivatestaticStringdecodeUnicode (finalStringdataStr ){
- Intstart = 0;
- Intend = 0;
- FinalStringBufferbuffer = newStringBuffer ();
- While (start>-1 ){
- Intsystem = 10; // hexadecimal
- If (start = 0 ){
- Intt = dataStr. indexOf ("&#");
- If (start! = T) start = t;
- }
- End = dataStr. indexOf (";", start + 2 );
- StringcharStr = "";
- If (end! =-1 ){
- CharStr = dataStr. substring (start + 2, end );
-
- // Judge the base
- Chars = charStr. charAt (0 );
- If (s = 'X' | s = 'X '){
- System = 16;
- CharStrcharStr = charStr. substring (1 );
- }
- }
- // Conversion
- Try {
- Charletter = (char) Integer. parseInt (charStr, system );
- Buffer. append (newCharacter (letter). toString ());
- } Catch (numberformateffectione ){
- E. printStackTrace ();
- }
-
- // Process non-unicode characters between the current unicode Character and the next unicode Character
- Start = dataStr. indexOf ("& #", end );
- If (start-end> 1 ){
- Buffer. append (dataStr. substring (end + 1, start ));
- }
-
- // Process the last non-unicode Character
- If (start =-1 ){
- Intlength = dataStr. length ();
- If (end + 1! = Length ){
- Buffer. append (dataStr. substring (end + 1, length ));
- }
- }
- }
- Returnbuffer. toString ();
- }
-