Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 字符串中的字符数_Ios_Objective C_Unicode_Nsstring - Fatal编程技术网

Ios 字符串中的字符数

Ios 字符串中的字符数,ios,objective-c,unicode,nsstring,Ios,Objective C,Unicode,Nsstring,我需要一种方法来查找NSString中的字符数。我的应用程序需要许多多字符unicode字符,这给NSString上的length方法带来了明显的问题 复制自苹果开发者网站: Length Returns the number of Unicode characters in the receiver. - (NSUInteger)length Return Value The number of Unicode characters in the receiver. 我不想要字符数

我需要一种方法来查找
NSString
中的字符数。我的应用程序需要许多多字符unicode字符,这给
NSString
上的
length
方法带来了明显的问题

复制自苹果开发者网站:

Length  
Returns the number of Unicode characters in the receiver. 
- (NSUInteger)length  
Return Value The number of Unicode characters in the receiver.

我不想要字符数本身,而是想要如果打印出字符串,您将看到的字符数。我在应用程序中使用的一些字符是带下划线的数字和字母,即0̄。在unicode中,这是用两个单独的unicode字符表示的,但是,当打印时,它是一个单独的实体。在查找字符串长度时,我需要像0这样的字符,以便只计算为一个,而不是像
NSString length
方法那样计算为两个。有没有办法做到这一点?谢谢。

您可以使用
NSStringEnumerationByComposedCharacterSequences
选项:


NSString*string=@“0”,谢谢你的回答。这似乎是一种很好的可靠的方法,可以完成我需要做的事情。我马上就接受这一点,u块做什么?@Iowa15:
u块
允许你从
内部修改
计数
变量
block.@Iowa15:
\uu block
在这里解释:。可能值得将其包装成一个分类方法,并将其粘贴到您的标准库中(遗憾的是,苹果没有这样做)。嗨,洛娃,也许您可以阅读我对这个问题的回答: