السلام عليكم يمكنك استخدام TStringList مع خاصية Delimiter حيث تضع فيها المحدد الذي يفصل بين النصوص و تضع في خاصية DelimitedText النص المراد اجراء العملية عليه ثم تقوم بتحميل النص الى stringlist يتم التقسيم بطريقة الية ابحث في المنتدى هناك الكثير مما اثير حول الموضوع
مثال :
PHP كود :
procedure TForm1.Button1Click(Sender: TObject); begin SplitText(Memo1, ';'); end;
PHP كود :
procedure TForm1.SplitText(AMemo: TMemo; Delimiter: Char); var StringList: TStringList; I: Integer; begin StringList := TStringList.Create; try StringList.Delimiter := Delimiter; StringList.DelimitedText := AMemo.Text; AMemo.Clear; for I := 0 to StringList.Count - 1 do AMemo.Lines.Add(StringList[I]); finally StringList.Free; end; end;
و لرب نازلة يضيق لها الفتى ذرعا و عند الله منها المخرج ضاقت فلما استحكمت حلقاتها فرجت و كنت اضنها لا تفرج
// By SMP3 function SplitStr(const AStr: String; n: integer): string; var s, PropStr: PChar; Len, MemLen, i, D: integer; c: char; MemTxt, FTxt, TmpStr: string; begin D := 0; MemTxt := AStr; Len := Length(MemTxt); GetMem(PropStr, Len * 2); MemLen := Len {$IFDEF UNICODE} * 2{$ENDIF}; s := PChar(MemTxt); for i := 0 to Len {$IFDEF UNICODE} * 2{$ENDIF} do begin if s^ <> #$D then begin inc(s); if s^ <> #$A then begin dec(s); PropStr^ := s^; inc(s); inc(D); inc(PropStr); end else begin inc(D); inc(s, 2); PropStr^ := ' '; inc(PropStr); end; end else begin inc(D); inc(s, 2); PropStr^ := ' '; inc(PropStr); end; end;
function SplitStr(const AStr: String; n: integer): string;
var
s, PropStr: PChar;
Len, MemLen, i, D: integer;
c: char;
MemTxt, FTxt, TmpStr: string;
begin
D := 0;
MemTxt := AStr;
Len := Length(MemTxt);
[COLOR="Red"] if Len < n then
Result := AStr;[/COLOR]
.....
.....
.....
// By SMP3 function SplitStr(const AStr: String; n: integer): string; var s, PropStr: PChar; Len, MemLen, i, D: integer; c: char; MemTxt, FTxt, TmpStr: string; begin D := 0; MemTxt := AStr; Len := Length(MemTxt); if Len < n then Result := AStr;
GetMem(PropStr, Len {$IFDEF UNICODE} * 2{$ENDIF}); MemLen := Len {$IFDEF UNICODE} * 2{$ENDIF}; s := PChar(MemTxt); for i := 0 to Len {$IFDEF UNICODE} * 2{$ENDIF} do begin if s^ <> #$D then begin inc(s); if s^ <> #$A then begin dec(s); PropStr^ := s^; inc(s); inc(D); inc(PropStr); end else begin inc(D); inc(s, 2); PropStr^ := ' '; inc(PropStr); end; end else begin inc(D); inc(s, 2); PropStr^ := ' '; inc(PropStr); end; end;