![]() |
Position des X-ten Vorkommens eines Strings ermitteln
SirThornberry hat in
![]() ![]()
Delphi-Quellcode:
function GetPosNumX(const ASubStr, AFullStr: String; AFoundCnt: Word; AStartPos: Integer=1): Integer;
var LFoundCnt : Word; LCompCnt, LFullLen, LGiveback, LMax, LPos, LSubLen : Integer; LPtr1, LPtr2 : PChar; begin LFullLen := Length(AFullStr); LSubLen := Length(ASubStr); if (AStartPos < LFullLen - LSubLen + 2) then begin // An dieser Stelle incrementieren da wir sonst an 2 anderen Stelle // incrementieren müssten dec(AStartPos); LGiveback := 0; LFoundCnt := 0; LMax := LFullLen - LSubLen + 2; LPtr1 := PChar(AFullStr) + AStartPos; LPtr2 := PChar(ASubStr); for LPos := AStartPos to LMax do begin LCompCnt := 0; while (LCompCnt < LSubLen) and (LPtr1[LCompCnt] = LPtr2[LCompCnt]) do inc(LCompCnt); if LCompCnt = LSubLen then begin inc(LFoundCnt); if LFoundCnt = AFoundCnt then begin LGiveback := LPos + 1; Break; end; end; inc(Cardinal(LPtr1)); end; result := LGiveback; end else result := 0; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:25 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz