本帖最后由 otmac 于 2009-09-07 13:50:53 编辑

解决方案 »

  1.   

    找出com,net,org,cn之类的,再向左判断
    也可以利用URL的.用STRINGLIST来分段
      

  2.   

    但是这样就麻烦了吧,最后的可能还多的很,info,gov,获取还有没见过的,这样不太好吧。还有,如果输入的是baidu.com/abc/bcd.index,这样也要判断出主机名才行。
      

  3.   

    主机名就是短域名吧
    比如http://www.baidu.com
    的主机名就是baidu.com
    任务包含这个域名的主机名都为baidu.com
      

  4.   

    URL有特点的,可以考虑压缩URL再进行比较,用pos来压缩。
    先把串中的http://裁剪掉,然后在从左到右寻找第一个'/',包括此字符到最右端的串截掉,这样剩下的就是主机地址,例如http://www.baidu.com/bbs/index.html就会变成www.baidu.com
    然后在寻找pos('www.',url)=1的时候删除www.,这样就剩下串"baidu.com"。
    所有的URL都经过这个操作后再进行比较就可以判断正确了。
    在处理之前建议先用lowerCase统一大小写后再比较。
      

  5.   

    先用stringReplace把http://去掉
    然后用copy函数从前往后找到字符串'/',用delete把'/'和它后面的字符串删除
    这时剩下的为www.baidu.com部分
    再定义一个Tstringlist
    sl.text := stringReplace('www.baidu.com', '.', #13#10, [rfReplaceAll]);
    这时sl的最后两行即为你要的主机名吧这个有点麻烦,期待更好的解决办法
      

  6.   

    这个方法我也考虑过,可是如果是https,www1,www2呢,方法貌似就不通用了哦?
      

  7.   

    我在想,有没有什么API,网络编程有关的API,来达到这个目的?
      

  8.   

    baidu.com 与 www.baidu.com 是不同的,这两个可以映射到不同的IP。也就是说,有可能是不同的服务器。
      

  9.   


    uses Wininet;procedure TForm1.Button1Click(Sender: TObject);
    var
      urlComponment: LPURL_COMPONENTS;
      url: string;
      hostname: Pchar;
    begin
      GetMem(urlComponment, SizeOf(TURLComponents));
      ZeroMemory(urlComponment, SizeOf(TURLComponents));
      urlComponment.dwStructSize := SizeOf(TURLComponents);  urlComponment.dwHostNameLength := 1000;
      GetMem(hostname, urlComponment.dwHostNameLength);
      urlComponment.lpszHostName := hostname;  url := 'ftp://www.abc.baidu.com/a.asp?s=13k';
      InternetCrackUrlA(PChar(url), Length(url), ICU_ESCAPE, urlComponment^);
      Caption:=urlComponment.lpszHostName;
    end;
    取其它字段的时候,名字字段和对应长度的字段必须全不为0
      

  10.   

    uses IdURI;                  //      <--function TForm1.CH(url1,url2: string): boolean;
    var
      U1,U2: TIdURI;
    begin
      U1:= TIdURI.Create(url1);
      U2:= TIdURI.Create(url2);
      result:= U1.Host = U2.Host;
      U1.Free;
      U2.Free;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      if CH('http://topic.csdn.net/u/20090907/13/bd61f132-8201-4164-b1a5-7ea7001f750f.html?11223',
      'http://topic.csdn.net/u/20090906/17/20030fc5-6809-4f32-bd2c-20b5743d1e86.html?58345')
        then showmessage('same');
    end;
      

  11.   

    谢谢大家,这两天有点忙,没来CSDN,我试试各位大虾的办法哈~
      

  12.   

    thanx 4 all. especially wintergoes and dinoalex. thanx again~