views:

531

answers:

3

i have a string like this nsstring *mystring=@"RahulVyas"; now i want to add this ' so the new string would be 'RahulVyas'

any way to do this?

+3  A: 

How about:

NSString *newString = [NSString stringWithFormat:@"'%@'", mystring];
notnoop
tried but it shows /'RahulVyas/'
Rahul Vyas
where do it show this? Have you tried outputing newString through NSLog? Some context would help here.
notnoop
yes i have see it through nslog
Rahul Vyas
The slashes don't show up in my NSLog output, I'm afraid. Can you provide some context so we can debug?
notnoop
A: 

You just want to surround the string with single quotes, right? You can just use stringWithFormat:

mystring = [NSString stringWithFormat:@"'%@'", mystring];
Marc Charbonneau
tried but it shows /'RahulVyas/'
Rahul Vyas
A: 
NSString *mystring=@"'RahulVyas'";
NSLog(@"%@", mystring);

Seems to work just fine for me.

Warren Pena