2009-05-19 5 views

Répondre

22
NSData *bytes = [test dataUsingEncoding:NSUTF8StringEncoding]; 
+0

laissez-moi vous expliquer ce qu'est le NSData? et quel est le NSString .. comment il diffère de la chaîne (en Java)? – Raju

+0

Merci beaucoup pour votre aide ..by raju – Raju

+4

Et pour les octets réels, 'uint8_t * rawBytes = [bytes bytes]' –

3

Voulez-vous quelque chose comme ceci:

NSString *[email protected]"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
NSUInteger bytes = [test lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; 
NSLog(@"%i bytes", bytes); 
1
extension String { 
    var byteArray : [Byte] { 
     return Array(utf8) 
    } 
} 

mise à jour: Xcode • Swift 7.2.1 2.1.1

extension String { 
    var byteArray : [UInt8] { 
     return Array(utf8) 
    } 
} 

test:

"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] 
Questions connexes