比较网络上的字符串 [英] Comparing a string from the web
本文介绍了比较网络上的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSError *错误;
NSURL * theURL = [NSURL URLWithString:@http://mysite.com/test.asp];
NSString * test = [NSString stringWithContentsOfURL:theURL encoding:NSASCIIStringEncoding error:& error];
NSLog(@%@,test); //打印结果.. .does work
if(test ==this is a test){
NSLog(@File read);
} else {
NSLog(@Bad file);
}
我在这里做错了什么?我总是得到坏文件,但我知道它正在拉动文本。谢谢所有
damien
解决方案
你需要检查nil为好吧&使用isEqualToString函数进行比较。
if(test!= nil){
if([test isEqualToString:@这是一个测试]){
//等于
}
else {
//不等于
}
}
else {
NSLog(@Bad file);
}
hey all, i'm trying to read a file on the web that says "this is a test" and i wanna compare it... so here's what i got:
NSError *error;
NSURL *theURL = [NSURL URLWithString:@"http://mysite.com/test.asp"];
NSString *test = [NSString stringWithContentsOfURL:theURL encoding:NSASCIIStringEncoding error:&error];
NSLog(@"%@",test); //prints the results.. .does work
if(test == "this is a test"){
NSLog(@"File read");
} else {
NSLog(@"Bad file");
}
What am i doing wrong here? I always get "Bad file" but i know it's pulling in the text. Thanks all
damien
解决方案
You need to check for nil as well & use isEqualToString function for comparison.
if(test != nil){
if([test isEqualToString:@"this is a test"]) {
// equal
}
else{
// not equal
}
}
else{
NSLog(@"Bad file");
}
这篇关于比较网络上的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文