Skip to content

Instantly share code, notes, and snippets.

黑手 darkhandz

Block or report user

Report or block darkhandz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@darkhandz
darkhandz / String+GBKTrim.swift
Created Jan 10, 2018
Swift按GBK编码截取字符串
View String+GBKTrim.swift
import Foundation
extension String {
/// 用GBK编码时的长度
var gbkLength: Int {
let cfEncoding = CFStringEncodings.GB_18030_2000
let encoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEncoding.rawValue))
let gbkData = (self as NSString).data(using: encoding)!
let gbkBytes = [UInt8](gbkData)
return gbkBytes.count
You can’t perform that action at this time.