📄 iphone的中文问题解决.htm
字号:
max = len-1;<BR> int h =
0;<BR> int l =
0;<BR> int p =
0;<BR> int b =
256;<BR> char
big[2];<BR> for(int i = 0;
i < max;
i++){<BR> h
= (char)
(Text<I>);<BR> if(h
<
0){<BR> h
= b +
h;<BR> l
= (char) (Text[i +
1]);<BR> if(l
<
0){<BR> l
= b + (char) (Text[i +
1]);<BR> }<BR> if(h
== 161 && l ==
64){<BR> big[0]
= big[1] = ( char) (161 -
b);<BR> }<BR> else{<BR> p
= (h - 160) * 510 + (l - 1) *
2;<BR> @try{<BR> big[0]
= ( char) (b_gbTable[p] -
b);<BR> }<BR> @catch(NSException
*e){<BR> big[0]
=
45;<BR> }<BR> @try{<BR> big[1]
= ( char) (b_gbTable[p + 1] -
b);<BR> }<BR> @catch(NSException
*e){<BR> big[1]
=
45;<BR> }<BR> }<BR> Text<I>
=
big[0];<BR> Text[i
+ 1] =
big[1];<BR> i++;<BR> }<BR> }//for<BR> }//try<BR> @catch
(NSException *ex)
{<BR> NSLog(@"Exception at
GBToBig5 (byte[])gbToBig5 %@: %@",[ex name],[ex
reason]);<BR> }<BR> return
Text;<BR>}<BR><BR>- (NSString *) gb2big5:(NSString
*)inStr{<BR> NSString
*big5Str=inStr;<BR> @try{<BR>
if(nil == inStr || [inStr isEqualToString:@""])
{<BR>
big5Str=@"";<BR>
}<BR> NSInteger len=[inStr
lengthOfBytesUsingEncoding:gbEncoding];<BR> unsigned
char *buffer2=new unsigned
char[len];<BR> memset(buffer2,
0,
sizeof(buffer2));<BR> NSRange
rg=NSMakeRange(0,
len);<BR> <BR> [inStr
getBytes:(void *)buffer2 maxLength:(NSUInteger)len usedLength:(NSUInteger
*)NULL encoding:(NSStringEncoding)gbEncoding
options:(NSStringEncodingConversionOptions)INT_MAX range:(NSRange)rg
remainingRange:(NSRangePointer)NULL];<BR> unsigned
char *byteBig5=[self gbToBig5:(unsigned char *)buffer2
length:len];<BR> delete
buffer2;<BR> big5Str=
[[NSString alloc] initWithBytes:byteBig5 length:len
encoding:big5Encoding_HK];<BR> }<BR> @catch
(NSException *ex)
{<BR> NSLog(@"Exception at
GBToBig5 gb2big5 %@: %@",[ex name],[ex
reason]);<BR> }<BR> return
[big5Str autorelease];<BR>}<BR><BR>-
(void)loadTableData{<BR> @try{<BR> NSString
*tablepath = [[NSBundle mainBundle] pathForResource:@"gb-big5"
ofType:@"table"];<BR> NSInputStream
*istream=[[NSInputStream alloc]
initWithFileAtPath:tablepath];<BR> [istream
setDelegate:self];<BR> [istream
scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];<BR> bytesRead=0;<BR> [istream
open];<BR> <BR> }<BR> @catch(NSException
*ex){<BR> NSLog(@"Exception
at GBToBig5 loadTableData %@: %@",[ex name],[ex
reason]);<BR> }<BR>}<BR>-
(void)loadTabletoBuffer{<BR> b_gbTable=(char *)[
_data mutableBytes];<BR>}<BR>- (void)stream:(NSStream *)stream
handleEvent:(NSStreamEvent)eventCode
{<BR> switch(eventCode) {
<BR> case
NSStreamEventHasBytesAvailable:
<BR> {
<BR> if(!_data)
{
<BR> _data
= [[NSMutableData data] retain];
<BR> }
<BR> uint8_t
buf[1024];
<BR> unsigned
int len = 0;
<BR> len
= [(NSInputStream *)stream read:buf maxLength:1024];
<BR> if(len)
{
<BR> [_data
appendBytes:(const void *)buf length:len];
<BR> bytesRead+=len;
<BR> }
else {
<BR> NSLog(@"gb-big5.table
read finished");
<BR> }
<BR> break;
<BR> }
<BR> case
NSStreamEventEndEncountered:
<BR> {
<BR> [self
loadTabletoBuffer];<BR> [stream
close];
<BR> [stream
removeFromRunLoop:[NSRunLoop currentRunLoop]
<BR> forMode:NSDefaultRunLoopMode];
<BR> [stream
release];
<BR> stream
= nil; // stream is ivar, so reinit it
<BR> break;
<BR> }
<BR> } <BR>}<BR><BR> <BR>@end</SPAN><BR><BR><BR><FONT
color=gray>[ 此帖被yakie在2008-10-16 10:09重新编辑 ]</FONT></DIV></I></I></TH></TR>
<TR class="tr1 r_one">
<TH
style="BORDER-TOP-WIDTH: 0px; PADDING-LEFT: 15px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; VERTICAL-ALIGN: bottom; BORDER-RIGHT-WIDTH: 0px">
<DIV class=c id=w_2594></DIV>
<DIV class=tipad><SPAN style="FLOAT: right"><A title=顶端
href="javascript:scroll(0,0)">顶端</A> </SPAN><SPAN class=gray>Posted:
2008-09-19 10:54 | From:广东省深圳市 </SPAN><SPAN><A class=s3 title=回复此楼
style="CURSOR: pointer" onclick="postreply('回 1楼(yakie) 的帖子');">1
楼</A></SPAN> </DIV></TH></TR></TBODY></TABLE></DIV>
<DIV class="t t2">
<TABLE style="BORDER-TOP-WIDTH: 0px; TABLE-LAYOUT: fixed" cellSpacing=0
cellPadding=0 width="100%">
<TBODY>
<TR class=tr1>
<TH class=r_two style="WIDTH: 20%" rowSpan=2><B>yakie</B>
<DIV style="MARGIN: 0.3em 0px 0.4em 0.2em"></DIV>
<DIV class=user-pic>
<TABLE
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px">
<TBODY>
<TR>
<TD width=1><A
onmouseover="mt=setTimeout('read.open(\'showface_2\',\'sf_2\',\'4\');',700);"
style="CURSOR: pointer"
onmouseout=clearTimeout(mt);read.close();><IMG class=pic
src="iphone的中文问题解决.files/none.gif" border=0></A> </TD>
<TD style="VERTICAL-ALIGN: top"><SPAN
id=sf_2></SPAN></TD></TR></TBODY></TABLE></DIV>级别: <FONT
color=#555555>骑士</FONT><BR><IMG style="MARGIN: 0.2em 0px 0.6em"
src="iphone的中文问题解决.files/10.gif"><BR><SPAN class=user-info id=showface_2
style="DISPLAY: none"><SPAN class=user-infoWrap><SPAN class=co></SPAN><A
href="http://www.cocoachina.com/bbs/profile.php?action=show&uid=147"><IMG
title=查看作者资料 src="iphone的中文问题解决.files/profile.gif"></A> <IMG title=发送短消息
style="CURSOR: pointer"
onclick="sendmsg('pw_ajax.php','action=msg&touid=147','sf_2')"
src="iphone的中文问题解决.files/message.gif"><IMG title=加为好友
style="CURSOR: pointer" onclick="addfriend('147')"
src="iphone的中文问题解决.files/friends.gif"> <IMG title=对该用户使用道具
style="CURSOR: pointer"
onclick="sendmsg('pw_ajax.php','action=usertool&uid=147','sf_2')"
src="iphone的中文问题解决.files/magic.gif"> <BR>精华: <A class="s4 f9"
href="http://www.cocoachina.com/bbs/search.php?authorid=147&digest=1"
target=_blank>1</A> <BR>发帖: <SPAN class="s1 f9">229</SPAN><BR>威望: <SPAN
class="s2 f9">251 点</SPAN><BR>可可豆: <SPAN class="s3 f9">603
CB</SPAN><BR>贡献值: <SPAN class="s1 f9">11
点</SPAN><BR>iChat:<BR>GTalk:<BR>在线时间:42(小时)<BR><SPAN
class=gray>注册时间:2008-06-13<BR>最后登录:2008-10-16 </SPAN></SPAN></SPAN></TH>
<TH class=r_one id=td_2596
style="BORDER-TOP-WIDTH: 0px; PADDING-RIGHT: 15px; PADDING-LEFT: 15px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; OVERFLOW: hidden; WIDTH: 80%; PADDING-TOP: 5px; BORDER-RIGHT-WIDTH: 0px"
vAlign=top height="100%">
<DIV class=tiptop><SPAN class=fr><A style="CURSOR: pointer"
onclick="fontsize('small','2596')">小</A> <A style="CURSOR: pointer"
onclick="fontsize('middle','2596')">中</A> <A style="CURSOR: pointer"
onclick="fontsize('big','2596')">大</A></SPAN> <SPAN class=fl
style="WHITE-SPACE: nowrap"><A id=quote_2596 title=引用回复这个帖子
href="http://www.cocoachina.com/bbs/post.php?action=quote&fid=6&tid=562&pid=2596&article=2">引用</A>
<A id=recommend_2596 title=推荐此帖
href="http://www.cocoachina.com/bbs/operate.php?action=recommend&tid=562">推荐</A>
<A
href="http://www.cocoachina.com/bbs/post.php?action=modify&fid=6&tid=562&pid=2596&article=2">编辑</A>
</SPAN>
<DIV class=c></DIV></DIV>
<H1 class=fl id=subject_2596></H1>
<DIV class=c id=p_2596></DIV>
<DIV class=tpc_content id=read_2596>上述代码中的GBToBig5.m中的<BR>NSStringEncoding
big5Encoding=0x80000A03;<BR>NSStringEncoding
big5Encoding_HK=0x80000A06;<BR>NSStringEncoding
gbEncoding=0x80000631;<BR>在程序中用的时候自己代替.<BR>上面的类还需要有一个gb-big5.table文件,见附件<BR><BR>使用的时候,通过调用-
(NSString *) gb2big5:(NSString
*)inStr这个方法即可,输入GB2312码的简体中文,返回的就是Big繁体的string<BR><BR><BR><FONT
color=gray>[ 此帖被yakie在2008-09-19 11:02重新编辑 ]</FONT></DIV></TH></TR>
<TR class="tr1 r_one">
<TH
style="BORDER-TOP-WIDTH: 0px; PADDING-LEFT: 15px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; VERTICAL-ALIGN: bottom; BORDER-RIGHT-WIDTH: 0px">
<DIV id=att_192 style="MARGIN: 5px">描述:所需要的查表文件,解压到proj目录然后加入proj即可<BR>附件:
<IMG src="iphone的中文问题解决.files/zip.gif" align=absBottom> <A
href="http://www.cocoachina.com/bbs/job.php?action=download&pid=2596&tid=562&aid=192"
target=_blank><FONT color=red>gb-big5.table.zip</FONT></A> (14 K) 下载次数:2
</DIV>
<DIV class=c id=w_2596></DIV>
<DIV class=tipad><SPAN style="FLOAT: right"><A title=顶端
href="javascript:scroll(0,0)">顶端</A> </SPAN><SPAN class=gray>Posted:
2008-09-19 10:56 | From:广东省深圳市福田区 </SPAN><SPAN><A class=s3 title=回复此楼
style="CURSOR: pointer" onclick="postreply('回 2楼(yakie) 的帖子');">2
楼</A></SPAN> </DIV></TH></TR></TBODY></TABLE></DIV>
<DIV class="t t2">
<TABLE style="BORDER-TOP-WIDTH: 0px; TABLE-LAYOUT: fixed" cellSpacing=0
cellPadding=0 width="100%">
<TBODY>
<TR class=tr1>
<TH class=r_two style="WIDTH: 20%" rowSpan=2><B>yakie</B>
<DIV style="MARGIN: 0.3em 0px 0.4em 0.2em"></DIV>
<DIV class=user-pic>
<TABLE
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px">
<TBODY>
<TR>
<TD width=1><A
onmouseover="mt=setTimeout('read.open(\'showface_3\',\'sf_3\',\'4\');',700);"
style="CURSOR: pointer"
onmouseout=clearTimeout(mt);read.close();><IMG class=pic
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -