procedure splitDatas(Lines, Keys, Values: TStrings); var N, P1, P2, L: integer; S, K, V: string; begin Keys.BeginUpdate; Values.BeginUpdate; try Keys.Clear; Values.Clear; for N := 0 to Lines.Count - 1 do begin S := Lines[N]; P1 := 1; P2 := pos(',', S); L := Length(S); K := ''; V := ''; // no invalid row if P2 <> 0 then begin // copy Key K := copy(S, P1, P2-P1); P1 := P2+1; P2 := L; // trim left while (S[P1] in #9) and (P1 <= L) do inc(P1); // trim right while (S[P2] in #9, #10, #13) and (P2 > 1) do dec(P2); if (P1 <= P2) and (P2<>0) then // copy Value V := copy(S, P1, P2-P1+1); // no null key and value if (K <> '') and (V <> '') then begin Keys.Add(K); Values.Add(V); end; end; end; finally Values.EndUpdate; Keys.EndUpdate; end; end;
splitDatas(MemoDatas.Lines, MemoKeys.Lines, MemoValues.Lines);
procedure TForm1.Trucmuche; var z:string; begin memo2.clear; memo3.clear; for i:=0 to memo1.Lines.Count-1 do begin z := memo1.lines[i]; memo2.lines.add(copy(z,1,pos(',',z)-1); memo3.lines.add(trim(copy(z,pos(',',z)+1,length(z)))); end; end;
var z:string; i:integer;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprocedure TForm1.Button1Click(Sender: TObject); var i, j, test: integer; ligne, concaN, concaC: string; begin for i := 0 to Memo1.Lines.Count - 1 do begin for j := 1 to length(Memo1.Lines.Strings[i]) do begin ligne := Memo1.Lines.Strings[i]; case TryStrToInt(Ligne[j], test) of true: concaN := concaN + Ligne[j]; false: concaC := concaC + Ligne[j]; end; if (Ligne[j] = ' ') or (j = length(Ligne)) then begin if concaN <> '' then Memo2.Lines.Add(concaN) else if concaC <> '' then Memo3.Lines.Add(concaC); concaN := ''; concaC := ''; end; end; end; end;
procedure TForm1.Button1Click(Sender: TObject); var i: Integer; s: string; CommaPos: Integer; P: PChar; begin Memo2.Clear; Memo3.Clear; for i := 0 to Memo1.Lines.Count - 1 do begin s := Memo1.Lines[i]; CommaPos := Pos(',', s); s[CommaPos] := #0; Memo2.Lines.Add(s); P := @s[CommaPos + 2]; Memo3.Lines.Add(P); end; end;
Merci pour ta réponse, mais cette fonction copie toutes les lignes avec les caractères et les chiffres.
Jojo, 5100
Robert, 2701
Foufou, 2651
Sara, 1, 21-29, 31-60, 990-1000
Jojo, 5100
Robert, 2701
Foufou, 2651
Sara, 1, 21-29, 31-60, 990-1000
procedure TForm1.Trucmuche; var z:string; i:integer; begin memo2.clear; memo3.clear; for i:=0 to memo1.Lines.Count-1 do begin z := memo1.lines[i]; memo2.lines.add(copy(z,1,pos(',',z)-1)); memo3.lines.add(trim(copy(z,pos(',',z)+1,length(z)))); end; end;