字符取值的问题如:(F:/aa/bb/cc.avi),现在我要取出bb/cc.avi怎么取? 在线等待!!!!! (30分)

  • 主题发起人 主题发起人 meet
  • 开始时间 开始时间
M

meet

Unregistered / Unconfirmed
GUEST, unregistred user!
字符取值的问题如:(F:/aa/bb/cc.avi),现在我要取出bb/cc.avi怎么取?<br>当然F:/aa/bb/cc.avi这只是一个例子还可能是F:/aaaa/bbbb/cc.avi,结果<br>是文件名和它的上一级目录一起取出
 
fdsafdasfdafdsaf
 
Application.terminate.
 
最后是我赢得
 
&nbsp;str:='F:/aaaa/bbbb/cc.avi';<br>&nbsp; while pos('/',str)&gt;0 do<br>&nbsp; begin<br>&nbsp; &nbsp; tmp:=str;<br>&nbsp; &nbsp; delete(str,1,pos('/',str));<br>&nbsp; end;<br>&nbsp; showmessage(tmp);<br><br>tmp就是你想要的
 
用COPY函数就可以了
 
to lysandria:<br>Copy函数可以你写点代码试试,,,,
 
&nbsp;str := 'c:/aaa/bbb/ccc.com';<br>&nbsp; R := StrScan(pchar(str), '/');<br>&nbsp; {R = '/aaa/bbb/ccc.com'}<br>自己想办法!
 
i := lastdelimiter('/',copy(str,1,lastdelimiter('/',str)-1));//i 是integer型<br>&nbsp;copy(str,i+1,length(str)-i); //i是倒数第二个'/'的位置,
 
2002-2004年了,还没解决吗?<br><br>var<br>&nbsp; str:string;<br>&nbsp; L:TStringList;<br>begin<br>&nbsp; str:='c:/abc/cc/dd.avi';<br>&nbsp; L:=TStringList.Create;<br>&nbsp; L.Delimiter:='/';<br>&nbsp; L.DelimitedText:=str;<br><br>&nbsp;showMessage(L.Strings[l.Count-2]+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;L.Delimiter+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;L.Strings[l.count-1]);<br>&nbsp; L.Free;<br>end;
 
function Tform1.GetIt(Str:String):String;<br>var<br>&nbsp; tempStr:String;<br>&nbsp; ReStr:String;<br>&nbsp; ipos:Integer;<br>begin &nbsp; &nbsp;//F:/aaaa/bbbb/cc.avi<br>&nbsp; ipos := pos('/',Str);<br>&nbsp; tempStr := Str;<br>&nbsp; while ipos&lt;&gt;0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; tempStr := copy(tempStr,ipos+1,length(tempStr)-ipos);<br>&nbsp; &nbsp; &nbsp; ipos := pos('/',tempStr);<br>&nbsp; &nbsp; &nbsp; if ipos&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; ReStr := tempStr;<br>&nbsp; &nbsp; end;<br>&nbsp; Result := ReStr;<br>end;<br><br>这样就ok了, :)
 
我的方法不行??
 
function Tform1.GetIt(Str:String):String;<br>var<br>&nbsp;tempStr:String;<br>&nbsp;ReStr:String;<br>&nbsp;ipos:Integer;<br>begin &nbsp; &nbsp;//F:/aaaa/bbbb/cc.avi<br>&nbsp;ipos := pos('/',Str);<br>&nbsp;tempStr := Str;<br>&nbsp;while ipos&lt;&gt;0 do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;tempStr := copy(tempStr,ipos+1,length(tempStr)-ipos);<br>&nbsp; &nbsp; &nbsp;ipos := pos('/',tempStr);<br>&nbsp; &nbsp; &nbsp;if ipos&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp;ReStr := tempStr;<br>&nbsp; &nbsp;end;<br>&nbsp;Result := ReStr;<br>end;<br><br>这样就ok了, :) &nbsp;<br>
 
to XWHope<br>你的方法行,,,分为给你了,,,
 
后退
顶部