String split extension splitex [delphi]

xiaoxiao2021-03-06  39

Didi.04-9-10 Teacher's Day

Function splitex (const str {requires a split article}, Delimiters {split keyword, Enter.?! etc.}: string: tstringlist;

VAR

SS: WideString;

I, st: integer;

Function isdelimiter (Const Delimiters, C: String): Boolean;

Begin // Judging whether it is a split key

Result: = STRSCAN (Pchar (Delimiters), C [1]) <> nil;

END;

Begin

Result: = TSTRINGLIST.CREATE;

WITH RESULT DO

Begin

Clear; sORTED: = true; duplicates: = dupignore DUPIGNORE

END;

IF Length (STR) <1 THEN EXIT;

SS: = Str; // Double character support, pure English can go

ST: = -1;

For i: = 1 to Length (ss) DO

IF Isdelimiter (Delimiters, SS [I]) THEN

IF ST <> -1 Then

Begin

Result.Add (TRIM (Copy (SS, ST, I - ST)));

ST: = -1;

end

Else

IF st = -1. ST: = I;

IF st <> -1 Then Result.Add (Copy (SS, ST, Length (STR)));

END;

// Operation Demo

With splitex (Memo1.text, ',,.?!' # 13 # 10) DO

Try

Savetofile ('c: /TEMP_DEMO.TXT');

Finally

FREE;

END;

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

New Post(0)