开发者

How is stringWithFormat used here?

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

html = [html stringByReplacingOccurrencesOfString:
           [NSString stringWithFormat:@"%@>", te开发者_如何学Goxt] withString:@""];

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

thanks


%@ 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜