V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
xpol
V2EX  ›  iDev

怎么把编码为 GB18030 的 UnsafePointer<Int8> 转换成 Swift 3 的字符串?

  •  
  •   xpol · 2016-10-15 23:37:39 +08:00 · 4284 次点击
    这是一个创建于 2720 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我通过 C 库获得的字符串,结果类型在 Swift 3 里面是 UnsafePointer<Int8>,编码是 GB18030 或者是 WIndows 的 CP936 。怎么把这个字符串转换成 Swift 3 的字符串啊? String.Encoding 下面找不到对应 GB18030 或者 CP936 的值。
    3 条回复    2016-10-16 09:34:29 +08:00
    Andy00
        1
    Andy00  
       2016-10-16 01:04:25 +08:00
    Core Foundation 里有一个叫 CFStringEncodings 枚举,里面有 GB18030 的编码,你可以试试
    具体详情见 http://stackoverflow.com/questions/29121906/how-to-change-gb-2312-encoding-to-utf-8
    sobigfish
        2
    sobigfish  
       2016-10-16 01:44:31 +08:00
    CP936 就是 GBK 么?
    ls 贴的那个就可以了, GB18030 兼容 GBK
    xpol
        3
    xpol  
    OP
       2016-10-16 09:34:29 +08:00
    就是:

    private static let GB_18030_2000 = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_18030_2000.rawValue)))

    好长。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5298 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:29 · PVG 17:29 · LAX 02:29 · JFK 05:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.