开发者

Shorten an NSString?

开发者 https://www.devze.com 2023-01-08 12:39 出处:网络
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?

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

精彩评论

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