ios - 在 SQLite 中处理编码的困难
<p><p>我正在尝试从 SQLite 文件中获取信息,当我运行查询时,信息以 ASCII 编码返回。我正在使用下面的代码将返回的信息放入一个字符串中。</p>
<pre><code>;
</code></pre>
<p>当我尝试使用 UTF8 编码将返回的信息放入字符串时,它不起作用。以下代码用于当前商店的应用程序中。</p>
<pre><code>;
</code></pre>
<p>字符串为空。如何转换 SQLite 文件以使其使用 UTF8 编码?商店的当前版本的应用程序使用上面的后一个代码,所以我需要弄清楚如何转换文件,而不是更改应用程序中的代码。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以将 <code>const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);</code> 与 <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/clm/NSString/stringWithCharacters:length:" rel="noreferrer noopener nofollow">stringWithCharacters:length:</a> 一起使用(UTF16)</p>
<pre><code>const unichar *text = sqlite3_column_text16(_sqlite_stmt, columnIndex);
if (text) {
NSUInteger length = sqlite3_column_bytes16(_sqlite_stmt, columnIndex)/sizeof(unichar);
article = ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在 SQLite 中处理编码的困难,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18211860/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18211860/
</a>
</p>
页:
[1]