- en snor i et dynamisk system

, en funktion, der opsplitter en snor i dele adskilt af et substring, og returnerer de dele i en dynamisk snor system, deler en snor i et system,,,, følgende funktioner og dele en snor i dele adskilt af et substring og returnerer de dele i en dynamisk snor system:,,,,,,, - grænseflade, tstringarray = antal snor,,,, funktion split (denne tlf: string;,, i denne separator: string = ","): tstringarray;,, funktion ansisplit (denne tlf: string;,, konstant - separator: string = ", '): tstringarray;,,, gennemførelse,,, anvender sysutils;,,, funktion split (denne tlf: string;,, denne separator: string): tstringarray; //returns an array with the parts of "str" separated by "separator",, var,, i, n: integer;,, p, q, s: PChar;,, begin,, SetLength(Result, Occurs(str, separator)+1);,, p := PChar(str);,, s := PChar(separator);,, n := Length(separator);,, i := 0;,, repeat,, q := StrPos(p, s);,, if q = nil then q := StrScan(p, #0);,, SetString(Result[i], p, q - p);,, p := q + n;, , , inc(i);,, until q^ = #0;,, end;,,, function AnsiSplit(const str: string;,, const separator: string): TStringArray;,, //Returns an array with the parts of "str" separated by "separator",, //ANSI version,, var,, i, n: integer;,, p, q, s: PChar;,, begin,, SetLength(Result, AnsiOccurs(str, separator)+1);,, p := PChar(str);,, s := PChar(separator);,, n := Length(separator);,, i := 0;,, repeat,, q := AnsiStrPos(p, s);,, if q = nil then q := AnsiStrScan(p, #0);,, SetString(Result[i], p, q - p);,, p := q + n;,, inc(i);,, until q^ = #0;,, end;,,, Example:,,, procedure TForm1.Button1Click(Sender: TObject);,, var,, a: TStringArray;,, i: integer;,, begin,, a := Split('part1,part2,part3');,, for i := 0 to Length(a) - 1 do begin //Will show three dialogs,, ShowMessage(a[i]); //'part1', 'part2', 'part3',, end;,, end;,,, You can see an example using a StringList instead of a dynamisk system i en særskilt artikel.



Previous:
Next Page: