﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-ivy-jie-文章分类-symbian </title><link>http://www.cppblog.com/ivy-jie/category/10753.html</link><description>progress ...</description><language>zh-cn</language><lastBuildDate>Tue, 07 Jul 2009 01:09:45 GMT</lastBuildDate><pubDate>Tue, 07 Jul 2009 01:09:45 GMT</pubDate><ttl>60</ttl><item><title>Symbian中文处理</title><link>http://www.cppblog.com/ivy-jie/articles/89169.html</link><dc:creator>ivy-jie</dc:creator><author>ivy-jie</author><pubDate>Fri, 03 Jul 2009 08:40:00 GMT</pubDate><guid>http://www.cppblog.com/ivy-jie/articles/89169.html</guid><wfw:comment>http://www.cppblog.com/ivy-jie/comments/89169.html</wfw:comment><comments>http://www.cppblog.com/ivy-jie/articles/89169.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ivy-jie/comments/commentRss/89169.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ivy-jie/services/trackbacks/89169.html</trackback:ping><description><![CDATA[<p>Symbian里面使用ConvertFromUnicodeToUtf8转换中文为什么是乱码?转换英文是正常的。因为要把16位的Unicode汉字保存到文件，所以必须转换成UTF8。<br>1 &nbsp;void MyUnicode2Utf8::ToUtf8FromUnicode(TDesC16 &amp;aUnicode)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; if(ibuf8) delete ibuf8;<br>&nbsp;&nbsp;&nbsp;&nbsp; if(ibuf) delete ibuf;<br><br>&nbsp; &nbsp;<font color=red>/&nbsp;/ 如果是中文字符, 这里乘3是正确的, 但是如果是英文就会有问题, 因为它占不满, 所以会有空格出现</font><br>&nbsp;&nbsp;&nbsp; int len = aUnicode.Length() * 3 + 1;&nbsp; <br>&nbsp;&nbsp;&nbsp; ibuf8 = HBufC8::NewL(len);<br>&nbsp;&nbsp;&nbsp; ibuf = HBufC::NewL(len); <br>&nbsp;&nbsp;&nbsp; TPtr8 ptrUtf8 = ibuf8-&gt;Des(); <br>&nbsp;&nbsp;&nbsp; CnvUtfConverter::ConvertFromUnicodeToUtf8(ptrUtf8, aUnicode); <br>&nbsp;&nbsp;&nbsp; ibuf-&gt;Des().Copy(ptrUtf8);<br>}<br><br>2 The second one takes each character and convert it to the other format. The 16-bit to 8-bit conversion may not always succeed in this case:<br>&nbsp; Code:<br>&nbsp; // Get a iBuf8 from a iBuf16 (data are modified)<br>&nbsp; CnvUtfConverter::ConvertFromUnicodeToUtf8(iBuf8,iBuf16); </p>
<p>&nbsp; // Get a iBuf16 from a iBuf8 (data are modified)<br>&nbsp; CnvUtfConverter::ConvertToUnicodeFromUtf8(iBuf16,iBuf8); </p>
<p>&nbsp;&nbsp; This second method requires to include the utf.h header and to link against charconv.lib.</p>
<img src ="http://www.cppblog.com/ivy-jie/aggbug/89169.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ivy-jie/" target="_blank">ivy-jie</a> 2009-07-03 16:40 <a href="http://www.cppblog.com/ivy-jie/articles/89169.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>