How do I insert a space to a NSString.
I need to add a space at index 5 into:
NString * dir = @"abcdefghijklmno";
To get this result:
abcde fghijklmno
with:
NSLOG (@"%@", dir);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to use
NSMutableStringor you could use those method to split your string :
and recombine them after with
But that way is more trouble that it’s worth. And since
NSStringis immutable, you would bet lot of object creation for nothing.Which can lead to difficult to debug problems.
That is the reason why
@propertyfor string are usually define ascopyso if you get aNSMutableString, by making a copy you are sure it won’t change because of some other unexpected code.I tend to prefer
s = [NSString stringWithString:mu];because you don’t get the confusion of copying a mutable object and having back an immutable one.