String form such as: http://img12.360buyimg.com/n2/g5/M02/12/11/rBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg
Requirements, all characters after the last "/", is shaped like rBEIDE_ym3gIAAAAAAH - cY - b9d4AADnwwG6zW4AAf6J330. JPG
How to do?
CodePudding user response:
var S: a string; The begin S:='http://img12.360buyimg.com/n2/g5/M02/12/11d/drBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg'. S:=ReverseString (s); S:=Copy (s, 1, Pos ('/', s) - 1); S:=ReverseString (s); CodePudding user response:
reference 1st floor chu_czx444 response: var S: a string; The begin S:='http://img12.360buyimg.com/n2/g5/M02/12/11d/drBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg'. S:=ReverseString (s); S:=Copy (s, 1, Pos ('/', s) - 1); S:=ReverseString (s); The first function ReverseString (const AText: string) : string; $[StrUtils pas The function returns a string AText antitone ReverseString (' 1234 ')='4321' Reference function System. SetLength Example Edit3. Text:=ReverseString (Edit1. Text); CodePudding user response:
function GetFileName (const sFilePath: string) : string; Var I, nLen: integer; The begin NLen:=length (sFilePath); For I:=nLen downto 1 do The begin If sFilePath [I]='/' then The begin Result:=copy (sFilePath, I + 1, nLen); exit; end; end; Result:='; end; Procedure TForm1. FormCreate (Sender: TObject); Const STR='http://img12.360buyimg.com/n2/g5/M02/12/11/rBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg'; The begin Caption:=GetFileName (STR); end; CodePudding user response:
This requirement is mainly character positioning, do not need to do the reverse CodePudding user response:
The reference 3 floor simonhehe response: function GetFileName (const sFilePath: string) : string; Var I, nLen: integer; The begin NLen:=length (sFilePath); For I:=nLen downto 1 do The begin If sFilePath [I]='/' then The begin Result:=copy (sFilePath, I + 1, nLen); exit; end; end; Result:='; end; Procedure TForm1. FormCreate (Sender: TObject); Const STR='http://img12.360buyimg.com/n2/g5/M02/12/11/rBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg'; The begin Caption:=GetFileName (STR); end; learning. CodePudding user response:
reference 4 floor simonhehe response: this demand is character positioning, don't need to do reverse Have a look at the code, inversion can faster as the '/', CodePudding user response:
refer to 6th floor farrellcn response: Quote: refer to 4th floor simonhehe response: This requirement is mainly character positioning, don't need to do reverse Have a look at the code, reverse can faster as the '/', This is ReverseString function, perform workload big The function ReverseString (const AText: string) : string; Var I: Integer; P: PChar; The begin SetLength (Result, Length (AText)); P:=PChar (Result); For I:=Length (AText) downto 1 do The begin P=AText ^ : [I]; Inc (P); end; end; Code quantity problem, write a custom function GetFileName, user invokes code amount is a line of CodePudding user response:
refer to the original poster u011577623 response: string form such as: http://img12.360buyimg.com/n2/g5/M02/12/11/rBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg Requirements, all characters after the last "/", is shaped like rBEIDE_ym3gIAAAAAAH - cY - b9d4AADnwwG6zW4AAf6J330. JPG How to do? With the SysUtils. StrRScan function is ok, Procedure TForm2. Button1Click (Sender: TObject); Var S: a string; The begin S:=SysUtils. StrRScan (' http://img12.360buyimg.com/n2/g5/M02/12/11/rBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg ', '/'); Memo1. Lines. The Add (Copy (s, 2, and Length (s) - 1)); end; CodePudding user response:
SysUtils. LastDelimiter var I: Integer; S: a string; The begin S:='http://img12.360buyimg.com/n2/g5/M02/12/11/rBEIDE_ym3gIAAAAAAH-cY-b9d4AADnwwG6zW4AAf6J330.jpg'. I:=LastDelimiter ('/', S); Delete (S, 1, I); ShowMessage (S) end; CodePudding user response:
Agreed to practice, 9/f, Reference to the practice of the Delphi system files