The nth position in the specified sub-string in the string is obtained, the efficiency is not high, barely available

xiaoxiao2021-03-06  43

Function GetnstringPOS (N: Integer; Substring, Astring: String): Integer;

/ / Return the location of the nth subString appears in Astring

// If you didn't find it, return -1

VAR

FINDCOUNT: Integer;

POS: integer;

Begin

RESULT: = -1;

POS: = 0;

For FINDCOUNT: = 1 to n Do Begin

INC (POS);

While Midstr (Astring, Pos, Length (Substring) <> Substring Do Begin

If Length (Astring)

Exit; // Not found

INC (POS);

END;

END;

Result: = POS;

END;

转载请注明原文地址:https://www.9cbs.com/read-72971.html

New Post(0)