开发者

is there a way to get the character count in a string? in obj c

hii every one

is there a way to get the character count in a string in ob开发者_StackOverflow中文版j c?

like how does the SMS app determine how big of a bubble the text view sends and receives? thanks a lot


You can use something like this:

NSString *str = @"Hello World!";
NSUInteger len = str.length;


If it is NSString then use str.length
If it is c string then use strlen(cString)


If it is a NSString then

[string length];

Not sure if you are talking about multi-bytes characters


length

Returns the number of Unicode characters in the receiver.

- (NSUInteger)length

Return Value

The number of Unicode characters in the receiver. Discussion

The number returned includes the individual characters of composed character sequences, so you cannot use this method to determine if a string will be visible when printed or how long it will appear.

NSLog(@"Length of your string is %d",[yourString length]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜