What is the length in bytes of a NSString?

后端 未结 4 1069
臣服心动
臣服心动 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:54

    To get the bytes use

    NSData *bytes = [string dataUsingEncoding:NSUTF8StringEncoding];
    

    Then you can check bytes.length

    Number of bytes depend on the string encoding

提交回复
热议问题