JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 程式分享區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
話題被移動
該話題已被移動 - browser , 2005-06-04 11:28
如果您尚不清楚該話題被移動的原因,請參考論壇規則以及本版公告或者聯系本版版主。
本主題所含的標籤
無標籤
作者 請問一下Java有辦法算出中文字的筆劃數嗎?
老陳





發文: 161
積分: 2
於 2005-05-30 09:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我最近想作一個有關索引查詢的系統,想要用程式自動計算一個中文字的筆劃數是多少?請問Java要怎麼作到呢?

reply to postreply to post
電腦是害人的工具,但是上帝卻可以藉著它行奇妙的大能
作者 Re:請問一下Java有辦法算出中文字的筆劃數嗎? [Re:老陳]
老陳





發文: 161
積分: 2
於 2005-06-04 09:34 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我想出解決辦法囉!原來網路上有人用Pascal已經寫好了這種程式,所以我就把它拿來改成Java囉!不過還是要標明一下出處

作者: 黎銘匡
介紹: 計算 BIG5 碼中文字的筆劃、計算字串的總筆劃及判斷某一個字元是否為中文的前導字元的函式 ( 附原始程式碼 )
程式下載位址: http://vcl.vclxx.org/DELPHI/D32FREE/CHARTW.ZIP
網頁位址: http://vcl.vclxx.org/DELPHI/AAAT102A.HTM


以下是我轉換成Java的Sample Code, 給大家參考,有不對的地方請指正 ^^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
public class Test {
    public static void main(String[] args) {
        try {
            int result = 0;
            String s = "網";
 
            byte[] bytes = s.getBytes();
            int b1 = (int) bytes[0] & 0xFF;
            int b2 = (int) bytes[1] & 0xFF;
 
            int b = (b1 << 8) + b2;
 
            // 一劃
            if ((b == 0xA440) || (b == 0xA441)) { 
                result = 1;
            }
            //2劃
            else if (((b >= 0xA442) && (b <= 0xA453)) || ((b >= 0xC940) && (b <= 0xC944))) { 
                result = 2;
            }
            //3劃
            else if (((b >= 0xA454) && (b <= 0xA47E)) || ((b >= 0xC945) && (b <= 0xC94C))) { 
                result = 3;
            }
            //4劃
            else if (((b >= 0xA4A1) && (b <= 0xA4FD)) || ((b >= 0xC94D) && (b <= 0xC962))) { 
                result = 4;
            }
            //5劃
            else if (((b >= 0xA4FE) && (b <= 0xA5DF)) || ((b >= 0xC963) && (b <= 0xC9AA))) { 
                result = 5;
            }
            //6劃
            else if (((b >= 0xA5E0) && (b <= 0xA6E9)) || ((b >= 0xC9AB) && (b <= 0xCA59))) { 
                result = 6;
            }
            //7劃
            else if (((b >= 0xA6EA) && (b <= 0xA8C2)) || ((b >= 0xCA5A) && (b <= 0xCBB0))) { 
                result = 7;
            }
            //8劃
            else if (((b == 0xA260) || (b >= 0xA8C3) && (b <= 0xAB44)) || ((b >= 0xCBB1) && (b <= 0xCDDC))) { 
                result = 8;
            }
            //9劃
            else if ((b == 0xA259) || (b == 0xF9DA) || ((b >= 0xAB45) && (b <= 0xADBB)) || ((b >= 0xCDDD) && (b <= 0xD0C7))) { 
                result = 9;
            }
            //10劃
            else if ((b == 0xA25A) || ((b >= 0xADBC) && (b <= 0xB0AD)) || ((b >= 0xD0C8) && (b <= 0xD44A))) { 
                result = 10;
            }
            //11劃
            else if ((b == 0xA25B) || (b == 0xA25C) || ((b >= 0xB0AE) && (b <= 0xB3C2)) || ((b >= 0xD44B) && (b <= 0xD850))) { 
                result = 11;
            }
            //12劃
            else if ((b == 0xF9DB) || ((b >= 0xB3C3) && (b <= 0xB6C2)) || ((b >= 0xD851) && (b <= 0xDCB0))) { 
                result = 12;
            }
            //13劃
            else if ((b == 0xA25D) || (b == 0xA25F) || (b == 0xC6A1) || (b == 0xF9D6) || (b == 0xF9D8) 
                    || ((b >= 0xB6C3) && (b <= 0xB9AB)) || ((b >= 0xDCB1) && (b <= 0xE0EF))) { 
                result = 13;
            }
            //14劃
            else if ((b == 0xF9DC) || ((b >= 0xB9AC) && (b <= 0xBBF4)) || ((b >= 0xE0F0) && (b <= 0xE4E5))) { 
                result = 14;
            }
            //15劃
            else if ((b == 0xA261) || ((b >= 0xBBF5) && (b <= 0xBEA6)) || ((b >= 0xE4E6) && (b <= 0xE8F3))) { 
                result = 15;
            }
            //16劃
            else if ((b == 0xA25E) || (b == 0xF9D7) || (b == 0xF9D9) || ((b >= 0xBEA7) && (b <= 0xC074)) 
                    || ((b >= 0xE8F4) && (b <= 0xECB8))) { 
                result = 16;
            }
            //17劃
            else if (((b >= 0xC075) && (b <= 0xC24E)) || ((b >= 0xECB9) && (b <= 0xEFB6))) { 
                result = 17;
            }
            //18劃
            else if (((b >= 0xC24F) && (b <= 0xC35E)) || ((b >= 0xEFB7) && (b <= 0xF1EA))) { 
                result = 18;
            }
            //19劃
            else if (((b >= 0xC35F) && (b <= 0xC454)) || ((b >= 0xF1EB) && (b <= 0xF3FC))) { 
                result = 19;
            }
            //20劃
            else if (((b >= 0xC455) && (b <= 0xC4D6)) || ((b >= 0xF3FD) && (b <= 0xF5BF))) { 
                result = 20;
            }
            //21劃
            else if (((b >= 0xC4D7) && (b <= 0xC56A)) || ((b >= 0xF5C0) && (b <= 0xF6D5))) { 
                result = 21;
            }
            //22劃
            else if (((b >= 0xC56B) && (b <= 0xC5C7)) || ((b >= 0xF6D6) && (b <= 0xF7CF))) { 
                result = 22;
            }
            //23劃
            else if (((b >= 0xC5C8) && (b <= 0xC5F0)) || ((b >= 0xF7D0) && (b <= 0xF8A4))) { 
                result = 23;
            }
            //24劃
            else if (((b >= 0xC5F1) && (b <= 0xC654)) || ((b >= 0xF8A5) && (b <= 0xF8ED))) { 
                result = 24;
            }
            //25劃
            else if (((b >= 0xC655) && (b <= 0xC664)) || ((b >= 0xF8EE) && (b <= 0xF96A))) { 
                result = 25;
            }
            //26劃
            else if (((b >= 0xC665) && (b <= 0xC66B)) || ((b >= 0xF96B) && (b <= 0xF9A1))) { 
                result = 26;
            }
            //27劃
            else if (((b >= 0xC66C) && (b <= 0xC675)) || ((b >= 0xF9A2) && (b <= 0xF9B9))) { 
                result = 27;
            }
            //28劃
            else if (((b >= 0xC676) && (b <= 0xC678)) || ((b >= 0xF9BA) && (b <= 0xF9C5))) { 
                result = 28;
            }
            //29劃
            else if (((b >= 0xC679) && (b <= 0xC67C)) || ((b >= 0xF9C7) && (b <= 0xF9CB))) { 
                result = 29;
            }
            //30劃
            else if ((b == 0xC67D) || ((b >= 0xF9CC) && (b <= 0xF9CF))) { 
                result = 30;
            }
            //31劃
            else if (b == 0xF9D0) { 
                result = 31;
            }
            //32劃
            else if ((b == 0xC67E) || (b == 0xF9D1)) { 
                result = 32;
            }
            //33劃
            else if ((b == 0xF9C6) || (b == 0xF9D2)) { 
                result = 33;
            }
            //35劃
            else if (b == 0xF9D3) { 
                result = 35;
            }
            //36劃
            else if (b == 0xF9D4) { 
                result = 36;
            }
            //48劃
            else if (b == 0xF9D5) { 
                result = 48;
            }
 
            System.out.println(s + "的筆劃數:" + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


為了讓大家兩邊對照方便,我把Pascal的程式附加上來喔~~ ^^

CharTw.pas (4.93k)


reply to postreply to post
電腦是害人的工具,但是上帝卻可以藉著它行奇妙的大能
作者 Re:請問一下Java有辦法算出中文字的筆劃數嗎? [Re:老陳]
gfhyang6379





發文: 5
積分: 0
於 2011-03-31 20:14 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問一下大大...上面這個程式我拿到 Android平台下面跑會有問題
發現是編碼格式不一樣,在 Windows上預設是 Big5
但是 Android上是 UTF-8。於是解出來的數值就不一樣了

請問有 UTF-8可以用的嗎?還是說可以將 UTF-8轉成 Big5?
謝謝


reply to postreply to post
作者 Re:請問一下Java有辦法算出中文字的筆劃數嗎? [Re:老陳]
me888





發文: 6
積分: 0
於 2015-12-22 09:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
This is a very good program, thanks

reply to postreply to post
作者 Re:請問一下Java有辦法算出中文字的筆劃數嗎? [Re:gfhyang6379]
roytsang





發文: 559
積分: 1
於 2016-01-08 17:40 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
試著用以下command 來compile 附件:

javac -encoding UTF8 Stroke.java

然後用以下command 來執行

java test.Stroke

Stroke.java (6.1k)


reply to postreply to post
» JWorld@TW »  Java 程式分享區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8