What is the length in bytes of a NSString?

后端 未结 4 1060
臣服心动
臣服心动 2021-02-05 06:03

How do I get the bytes length of NSString? if myString contains \"hallo\", myString.length will return 5, but how many actual bytes are ta

4条回答
  •  野性不改
    2021-02-05 06:32

    NSString *test=@"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    NSUInteger bytes = [test lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"%i bytes", bytes);
    

提交回复
热议问题