39

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"];
pasawaya
  • 11,515
  • 7
  • 53
  • 92
Umair Khan Jadoon
  • 2,874
  • 11
  • 42
  • 63

4 Answers4

75

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?

Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40
47

You can try this also:

you = [NSString stringWithFormat:@"%@%@", you, @"123"];
andrewsi
  • 10,807
  • 132
  • 35
  • 51
Spidey
  • 696
  • 8
  • 11
3

Code :

NSString *you;
you = @"This is you String!";
NSLog(@"you : %@ ",you);

you = [you stringByAppendingString:@"123"];
 NSLog(@"you : %@ ",you);

[you stringByAppendingFormat:@"%@%@",you,@"123"];
NSLog(@"you : %@ ",you);

Result in Console :

[233:907] you : This is you String!

[233:907] you : This is you String!123

[233:907] you : This is you String!123

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
  • No `you=` on the last one? And according to the log, don't the the meaning of this one. On the logs, there is a "tempString"... – Larme Jan 23 '14 at 08:02
  • @Larme : Dude that tempString was earlier code.. Why down vote? – Jayprakash Dubey Jan 23 '14 at 09:49
  • 2
    I didn't downvote. Still don't understand the last line. You show a different method, but you don't put `you =` before. Indeed, so the last log is normal, but still don't understand the meaning of this one to help the topic. – Larme Jan 23 '14 at 10:03
1

Please try this

NSString *version = @"14.5.1";

NSString *build = @"1.0";


self.versionLabel.text = [NSString stringWithFormat:@"%@%@%@%@%@" , @"V : " ,version,@" ( ",build, @" )" ];
Binoy jose
  • 461
  • 4
  • 9