URL主机比较 [英] URL host comparison

查看:56
本文介绍了URL主机比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我试图比较 2 个 URL 的主机.即使该主机是相同的,它也不会响应为什么!

Here I am trying to compare the hosts of 2 URLs. Even though that hosts are the same it does not respond why!

代码:

NSURL *url=[NSURL URLWithString:@"http://www.facebook.com/"?ref=logo" ];
    NSURL *domain=[ NSURL URLWithString:@"http://www.facebook.com" ];

    if ( [url host]==[domain host] ) {

        NSLog(@"hosts are matched");
    }else {
        NSLog(@"hosts are not matched!");
    }

推荐答案

你需要使用 isEqualToString:

NSURL *url=[NSURL URLWithString:@"http://www.facebook.com/?ref=logo" ];
NSURL *domain=[ NSURL URLWithString:@"http://www.facebook.com" ];

if ( [[url host] isEqualToString: [domain host]] ) {
    NSLog(@"hosts are matched");
}else {
    NSLog(@"hosts are not matched!");
}

结果

2011-11-23 11:55:06.182 TestApp[14404:207] 主机匹配

2011-11-23 11:55:06.182 TestApp[14404:207] hosts are matched

这篇关于URL主机比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆