1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class WhichEncoding {
24 public static String toHex(char a) {
25 char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
26 'A', 'B', 'C', 'D', 'E', 'F' };
27 int x = a & 0xFFFF;
28 int x1 = (x >>> 12) & 0x0F;
29 int x2 = (x >>> 8) & 0x0F;
30 int x3 = (x >>> 4) & 0x0F;
31 int x4 = x & 0x0F;
32
33 return "" + hex[x1] + hex[x2] + hex[x3] + hex[x4];
34 }
35
36 public static boolean isEucKr(String s) {
37 int len = s.length();
38 char c;
39 for (int i = 0; i < len; i++) {
40 c = s.charAt(i);
41
42 if (((c & 0xFFFF) >= 0xAC00) && ((c & 0xFFFF) <= 0xD7A3))
43 return true;
44
45
46 }
47 return false;
48 }
49
50 public static boolean isISO8859(String s) {
51 int len = s.length();
52 char c;
53 for (int i = 0; i < len; i++) {
54 c = s.charAt(i);
55
56 if ((c & 0xFF00) != 0)
57 return false;
58 }
59 return true;
60 }
61
62 public static void main(String[] args) {
63 try {
64
65 String a = " a ± b (단, ±는 복호 동순)";
66 String b = new String(a.getBytes("euc-kr"), "8859_1");
67 System.out.println("isEucKr(\"" + a + "\") --> " + isEucKr(a));
68 System.out.println("isEucKr(\"" + b + "\") --> " + isEucKr(b));
69 String c = " a ± b";
70 System.out.println("isISO8859(\"" + c + "\") --> " + isISO8859(c));
71 }
72 catch (java.io.UnsupportedEncodingException ex) {
73 }
74 }
75 }
CategoryJava
ZbmonWiki: WhichEncoding.java (2005-11-07 14:27:38에 zbmon가(이) 마지막으로 수정)