I want to trim a string to 50 characters (if it’s too long), so I decided to use the following method.
someString = [someString stringByPaddingToLength: 50 withString: @"" startingAtIndex: 0];
Can I pass an empty string after the withString argument? I don’t want to crash my app when the method tries to add the string until someString is 50 characters in length. I’m afraid it’s gonna be bad because it will have to iterate the string [someString length] / 0 times.
Should I use nil instead or search for another way to do the trimming?
Thank you.
I’m not quite sure why you’re using the
stringByPaddingToLength:...method, if you want to trim a string. I’d have thought that thesubstringToIndex:NSString method would be a more logical solution.For example: