网 网际飞鹰 Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-17 #1 例如:book.com_4545465_filename.txtcopycom_filename.txt结果filename.txtfilename.txt找了一些函数,似乎没有类似的。
X xnnfan126 Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-17 #3 A=字符串b=length(filename.txt)copy(A,length(A)-b+1,b)
网 网际飞鹰 Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-17 #4 文本是没有规律的,但有下划线在需留用的文件名之前。简而言之,要把文件名的下划线及之前的字符去掉。保留后面的真实的文件名。真实的文件名一般不重复。楼上的似乎也不能解决这个问题。
D delhpi Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-17 #5 uses StrUtilsvar i, R: integer str:string;begin str:='book.com_4545465_filename.txt' i:=1 repeat r:=PosEx('_',str,i) if r<>0 then i:=r+1 until (r=0) caption:=midstr(str,i,length(str)-i+1);end;
uses StrUtilsvar i, R: integer str:string;begin str:='book.com_4545465_filename.txt' i:=1 repeat r:=PosEx('_',str,i) if r<>0 then i:=r+1 until (r=0) caption:=midstr(str,i,length(str)-i+1);end;
D de410 Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-17 #6 uses StrUtilsprocedure TForm1.Button1Click(Sender: TObject);var i, n1,n2: integer str:string;begin str:='book.com_4545465_filename.txt' repeat n1:=length(str) i:=Pos('_',str) Delete(str,1,i) until(i=0) n2:=n1-i ShowMessage(str) end;
uses StrUtilsprocedure TForm1.Button1Click(Sender: TObject);var i, n1,n2: integer str:string;begin str:='book.com_4545465_filename.txt' repeat n1:=length(str) i:=Pos('_',str) Delete(str,1,i) until(i=0) n2:=n1-i ShowMessage(str) end;
D delhpi Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-17 #7 楼上的还送了几行代码。 n1:=length(str) n2:=n1-i;
网 网际飞鹰 Unregistered / Unconfirmed GUEST, unregistred user! 2009-05-18 #8 问题我已经自己解决,用的是自己的笨办法,先取长度,然后从后到前逐位检测是否有“_”,一旦遇到有“_”之后的就填“ ”空格,最后用trim()去掉空格ok。还是很感谢delphi de410 xunfan126热心解答。我的D6不支持PosEx函数,顺便贴上它的源码。这样D6也可以用了。function PosEx(const SubStr, S: string Offset: Cardinal = 1): Integer;varI,X: Integer;Len, LenSubStr: Integer;beginif Offset = 1 thenResult := Pos(SubStr, S)elsebeginI := Offset;LenSubStr := Length(SubStr);Len := Length(S) - LenSubStr + 1;while I <= Len dobeginif S = SubStr[1] thenbeginX := 1;while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) doInc(X);if (X = LenSubStr) thenbeginResult := I;exit;end;end;Inc(I);end;Result := 0;end;end;
问题我已经自己解决,用的是自己的笨办法,先取长度,然后从后到前逐位检测是否有“_”,一旦遇到有“_”之后的就填“ ”空格,最后用trim()去掉空格ok。还是很感谢delphi de410 xunfan126热心解答。我的D6不支持PosEx函数,顺便贴上它的源码。这样D6也可以用了。function PosEx(const SubStr, S: string Offset: Cardinal = 1): Integer;varI,X: Integer;Len, LenSubStr: Integer;beginif Offset = 1 thenResult := Pos(SubStr, S)elsebeginI := Offset;LenSubStr := Length(SubStr);Len := Length(S) - LenSubStr + 1;while I <= Len dobeginif S = SubStr[1] thenbeginX := 1;while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) doInc(X);if (X = LenSubStr) thenbeginResult := I;exit;end;end;Inc(I);end;Result := 0;end;end;