Convert to UTF8 code

xiaoxiao2021-03-06  85

/ **

* Convert to UTF8 code

* @Param s

* @Return

* /

Public static string toutf8string (string s) {

StringBuffer SB = new stringbuffer ();

For (int i = 0; i

CHAR C = S.Charat (i);

IF (c> = 0 && c <= 255) {

Sb.append (c);

} else {

Byte [] B;

Try {

B = String.Valueof (c) .getbytes ("UTF-8");

} catch (exception ex) {

System.out.println (ex);

B = new byte [0];

}

For (int J = 0; j

INT K = B [J];

IF (k <0)

K = 256;

sb.append ("%" integer.tohexstring (k) .touppercase ());

}

}

}

Return sb.toString ();

}

转载请注明原文地址:https://www.9cbs.com/read-94026.html

New Post(0)