likki
likki

Reputation: 359

How is stringWithFormat used here?

NSString *html="html page to parse";
NSString *text="some html text";

html = [html stringByReplacingOccurrencesOfString:
           [NSString stringWithFormat:@"%@>", text] withString:@""];

My question is what will @"%@>" will do in stringwithFormat.

thanks

Upvotes: 1

Views: 489

Answers (2)

KingofBliss
KingofBliss

Reputation: 15115

The code

html = [html stringByReplacingOccurrencesOfString:
           [NSString stringWithFormat:@"%@>", text] withString:@""];

will replace occurence of some html text> in html page to parse with empty string.

So the result will be html page to parse only.

Using stringWithFormat You can easily perform many operation such as converting an int/float value to string,etc.,

int age=18;

NSSring *myage=[NSString stringWithFormat:@"My age is %d", age];

Here the value of myage is My age is 18.

Upvotes: 1

Beaker
Beaker

Reputation: 1608

%@ tells NSString you will be including an object in your string, so it will try to parse it as a string. According to Apple, %@:

"Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function."

The first @ symbol simply denotes a NSString.

Apple documentation

Upvotes: 2

Related Questions