开发者

Shorten an NSString?

I h开发者_StackOverflow中文版ave a very simple question. Is there a built in method to shorten strings? If not can someone provide an example of doing that in ObjC?

For example:

ThisIsAVeryLongString

should become

ThisIsAV...

It needs to check if the string is over a certain amount of characters and if it is shorten it.


It's pretty straightforward...

NSString *originalString = @"SomethingVeryLong";
int newLength = 9;
if (originalString.length > newLength)
    NSString *shortString = [originalString substringToIndex:newLength];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜