| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1050 人关注过本帖
标题:处理一串字符串的时候.如何让他按照特定的分符得到
只看楼主 加入收藏
kissjetg
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-10-12
收藏
 问题点数:0 回复次数:1 
处理一串字符串的时候.如何让他按照特定的分符得到
首先。我得到的一串字符串是这个
http://forum.
我想要的是效果是
http://forum.
http://forum.
http://forum.
http://forum.
..不知道大伙明白不......我已经通过百度搜索了得到了一些按照特殊字符分隔号,


我写的代码得到了像上面的地址....
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c,aa,str:string;
i,ii:integer;
begin
str := 'http://localhost/blog/delphi/post/delphi字体.html';
a:=str;
aa:='';
delete(a,1,pos('/',a)+1);          //  --删除第一个/的起始,也就是http:/ + /
b:=copy(a,1,pos('/',a)-1);          //  --搜索/ ,因为上面的已经删除了前面的/,
b:='http://'+b;                  //    --所以这一次就从地址的xx.为结束得到网址完整
  for i := 3 to pos('/',str) do
    begin
    a:=GetListSubValue(str,'/',i); //getlistsbuvalue是网上的一个分割参数
    aa:=aa+'/'+a;
    memo1.Lines.Add(b+aa);
    end;


这是分割处的代码

function GetListSubValue(TotalValue: string;SplitStr: string;subIndex: integer): string;
var
  iPos: integer;
Label 1;
begin
  1:
  iPos := Pos(SplitStr,TotalValue);
  if ipos = 0 then  result := TotalValue
  else if subindex = 0 then
    result := Copy(TotalValue,1,ipos-1)
  else
  begin
    TotalValue := Copy(TotalValue,ipos+Length(SplitStr),MaxInt);
    if subIndex <> 0 then
    begin
      subIndex := subIndex - 1;
      goto 1;
    end;
  end;
  end;


但是虽然能得到了值。但是无论我换了几层目录都是会返回四个目录的数.
正常的目录
http://forum.
执行后
http://forum.  //多出了一个
http://forum.
http://forum.
http://forum.
http://forum.
--------------------------------------------------------------------------

我知道是我的算法有问题。所以想请各位朋友能帮帮忙,帮我改一下。就是无论这个地址是什么值。他就会按照目录多少次来进行得到他的目录.....
搜索更多相关主题的帖子: 字符 
2008-10-23 04:07
gykthh
Rank: 1
等 级:新手上路
威 望:1
帖 子:8
专家分:0
注 册:2007-6-10
收藏
得分:0 
是用“/”作为分隔符的 有四个“/" 所以只能是四次了
2008-11-10 10:50
快速回复:处理一串字符串的时候.如何让他按照特定的分符得到
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020739 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved