TExplodeArray = array of String;
function Explode(const cSeparator, vString: String): TExplodeArray; var i: Integer; S: String; begin //S := vString; S := ''; SetLength(Result, 0); i := 0; while Pos(cSeparator, S) > 0 do begin SetLength(Result, Length(Result) +1); Result[i] := Copy(S, 1, Pos(cSeparator, S) -1); Inc(i); S := Copy(S, Pos(cSeparator, S) + Length(cSeparator), Length(S)); end; SetLength(Result, Length(Result) +1); Result[i] := Copy(S, 1, Length(S)); end;
var tableauTemp1: TExplodeArray; tableauTemp2: TExplodeArray; //[...] tableauTemp1 := Explode('_', DirName); if Length(tableauTemp1) > 0 then begin EditVerInstalledGame.Text := tableauTemp1[1]+'.'+tableauTemp1[2]+'.'+tableauTemp1[3]; EditVerInstalledTrad.Text := tableauTemp1[4]; end;
uses Windows, SysUtils, Classes; type TStringList = class(Classes.TStringList) private fNoProtect: boolean; function getCSV: string; procedure setCSV(const Value: string); public property CSV: string read getCSV write setCSV; constructor CreateAsCSV(aProtector,aDelimiter: char); reintroduce; end; implementation { TStringList } constructor TStringList.CreateAsCSV(aProtector, aDelimiter: char); begin inherited; fNoProtect :aProtector #0; if not fNoProtect then QuoteChar := aProtector; Delimiter := aDelimiter; StrictDelimiter := true; end; function TStringList.getCSV: string; var N,L: integer; begin L := count-1; result := ''; for N := 0 to L do begin if fNoProtect then result := result + strings[N] else result := result + quoteChar + strings[N] + quoteChar; if N < L then result := result + Delimiter; end; end; procedure TStringList.setCSV(const Value: string); begin delimitedText := Value; end; end.
uses {....,} Classes,{ ....,} CSVList; {...} procedure BlaBlaBla; var TSL: TStringList; begin TSL := TStringList.CreateAsCSV(#0, '_'); try TSL.CSV := DirName; // 1_2_3_FR if TSL.Count=4 then begin EditVerInstalledTrad.Text := TSL[3]; // FR TSL.Delete(3); TSL.Delimiter := '.'; EditVerInstalledGame.Text := TSL.CSV; // 1.2.3 end; finally TSL.Free; end; end;