Rahul Vyas
Rahul Vyas

Reputation: 28730

How to add ' in NSString in ios sdk?

I have a NSString like this

NSString *mystring = @"RahulVyas";

Now I want to add this ' so the new string would be 'RahulVyas'

How to do this ?

Upvotes: 1

Views: 4120

Answers (3)

Warren Pena
Warren Pena

Reputation: 572

NSString *mystring=@"'RahulVyas'";
NSLog(@"%@", mystring);

Seems to work just fine for me.

Upvotes: 0

Marc Charbonneau
Marc Charbonneau

Reputation: 40515

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

mystring = [NSString stringWithFormat:@"'%@'", mystring];

Upvotes: 0

notnoop
notnoop

Reputation: 59307

How about:

NSString *newString = [NSString stringWithFormat:@"'%@'", mystring];

Upvotes: 6

Related Questions