Self-written lastpos, looking for the last character in the string, the RTL does not provide this function--delphi string subscript is starting from 1

Source: Internet
Author: User
Tags strfind

Already several times, without this function or feel very inconvenient, so I wrote a:

functionLastpos (strfind:string; ch:char): integer;varI, N:integer;beginResult:= -1; ifStrfind="'  Then    beginExit; End;  fori:=0  toLength (Strfind) Do    begin        ifStrfind[i]=ch ThenResult:=i; End;End;procedureTform1.button1click (sender:tobject);vars1:string;beginS1:='ABC'; ShowMessage (s1[1]); ShowMessage (IntToStr (Length ('/myaccount/save1/'))); ShowMessage (IntToStr (Lastpos ('/myaccount/save1/','/')));End;

Of course, there are no issues such as efficiency and Unicode, which are better for D7 anyway.

Another algorithm, see how others write it (reverse is not normal thinking):

function Lastpos (conststring; C:char): Integer; var     I:integer; begin     i:= Length (S);      while 0  and  Do         Dec (i);    Result:= i; End;

Self-written lastpos, looking for the last character in the string, the RTL does not provide this function--delphi string subscript is starting from 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.