Simple string concatenation in Objective C

Umair Khan Jadoon picture Umair Khan Jadoon · Jan 13, 2012 · Viewed 82.6k times · Source

I have an NSString named 'you' with value "This is a you string!".

I want to concat "123" in 'you', how can I do it?

I am using this code and it is giving an error.

you=[you stringByAppendingString:@"123"];

Answer

Vincent Bernier picture Vincent Bernier · Jan 13, 2012

This code here is working for me

NSString *s = @"avant";
s = [s stringByAppendingString:@" - après"];
NSLog(@"%@", s);

2012-01-13 11:48:59.442 tabbar[604:207] avant - après

So my guess is that your you is a bad pointer that is not nil and not the NSString you think it have.

Have you try an NSLog on that value before the call?