tags:

views:

106

answers:

1

Hi guys,

I am having a string which contains more the 25 characters;

NSString *str = @"This is the string to be truncated to 15 characters only";

In the above string I need only the 15 characters to be stored in another variable after truncation.

can anyone suggest me how to do this? Anyone's help will be much appreciated.

Thank you, Monish

+1  A: 
str = [str substringToIndex:15];

It throws an exception if the string contains less than 15 characters, of course.

tc.
So it would be a good idea to check the length before attempting this... if ([str length] > 15) { str = [str substringToIndex:15];}
Tom Irving