sloppycode.net
Instr function for Delphi
A small method to add to the Pos function.
Home
›
Code snippets
›
Delphi
›
Instr function for Delphi
One of the problems with the Pos function is that you can't specify a start position. This function solves this (n.b. this is from 2002 with Delphi 5).
function ClassName.instr(start: integer; original, search:String):Integer; begin // if the start is more than the length of the original string or start = 0 then if (start > Length(original)) or (start = 0) then Result:=0 // return 0 else // if the bit we are searching does not contain the text we are looking for then if Pos(search,Copy(original,start,Length(original)-start)) = 0 then Result:=0 // return 0 else // return start + the position of the text in the split bit // (start is needed to give the complete value for in the original string) Result := start+Pos(search,Copy(original,start,Length(original)-start)); end;
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search
› Sitemap
Buy on Amazon
Buy on Amazon
Buy on Amazon
Buy on Amazon