views:

59

answers:

2

I have 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.

+2  A: 

It's pretty straightforward...

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