菜鸟教程小白 发表于 2022-12-12 20:42:04

iphone - NSString UTF8String 处理 unicode 字符


                                            <p><p>当我在某些 unicode 字符上运行 <code></code> 时,生成的 <code>const char*</code> 表示在 <code>NSLog</code> 和设备上都会被破坏/模拟器显示。 <code>NSString</code> 本身显示正常,但我需要将 <code>NSString</code> 转换为 <code>cStr</code> 以在 <code>CGContextShowTextAtPoint</code> 中使用它。</p>

<p>很容易重现(见下面的代码),但我搜索了类似的问题,但没有任何运气。一定是我缺少的一些基本的东西。</p>

<pre><code>const char *cStr = [@&#34;章&#34; UTF8String];
NSLog(@&#34;%s&#34;, cStr);
</code></pre>

<p>谢谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><code>CGContextShowTextAtPoint</code> 仅适用于 ASCII 字符。</p>

<p>检查 <a href="https://stackoverflow.com/questions/1237565/iphone-cgcontextshowtextatpoint-for-japanese-characters" rel="noreferrer noopener nofollow">this</a> SO问题的答案。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - NSString UTF8String 处理 unicode 字符,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/10468671/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/10468671/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - NSString UTF8String 处理 unicode 字符