公告
财富商城
积分规则
提问
发文
2019-01-25 06:23发布
干净又极端
NSString *test = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
How to convert this string to bytes?
NSData *bytes = [test dataUsingEncoding:NSUTF8StringEncoding];
extension String { var byteArray : [Byte] { return Array(utf8) } }
update: Xcode 7.2.1 • Swift 2.1.1
extension String { var byteArray : [UInt8] { return Array(utf8) } }
testing:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".byteArray // [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90]
Do you want something like this:
NSString *test=@"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; NSUInteger bytes = [test lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%i bytes", bytes);
最多设置5个标签!
update: Xcode 7.2.1 • Swift 2.1.1
testing:
Do you want something like this: