Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 这里如何使用stringWithFormat?_Iphone_Nsstring - Fatal编程技术网

Iphone 这里如何使用stringWithFormat?

Iphone 这里如何使用stringWithFormat?,iphone,nsstring,Iphone,Nsstring,我的问题是@“%@>”将在stringwithFormat中做什么 感谢%@告诉NSString您将在字符串中包含一个对象,因此它将尝试将其解析为字符串。据苹果称,%@: Objective-C对象,打印为descriptionWithLocale:或description返回的字符串(如果可用)。也可用于CFTypeRef对象,返回CFCopyDescription函数的结果 第一个@符号仅表示一个NSString 代码 NSString *html="html page to parse";

我的问题是
@“%@>”
将在stringwithFormat中做什么


感谢

%@告诉NSString您将在字符串中包含一个对象,因此它将尝试将其解析为字符串。据苹果称,%@:

Objective-C对象,打印为descriptionWithLocale:或description返回的字符串(如果可用)。也可用于CFTypeRef对象,返回CFCopyDescription函数的结果

第一个@符号仅表示一个NSString

代码

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

html = [html stringByReplacingOccurrencesOfString:
           [NSString stringWithFormat:@"%@>", text] withString:@""];
将用空字符串替换html页面中出现的某些html文本>,以分析

因此,结果将是只需解析的html页面

使用stringWithFormat,您可以轻松执行许多操作,例如将int/float值转换为字符串等

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

这里myage的值是我的年龄是18

,这样NSString将变成
一些html文本>
[html stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]太棒了!。所以,如果我把%@A放进去,上面的代码将把字符串A替换为“”不是吗?
int age=18;

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