Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > help to split text in richedit how ?


Автор: huismori 1.12.2010, 20:50
i want to split text in richedit after every 500 characters, is it possible ?

Автор: muratboy31 3.12.2010, 15:22
i saw something like that on the net and i tried to find it again but i could find it... sorry !!!

Автор: huismori 3.12.2010, 15:25
it would be good if you could have found it again...
i also searched on the net but no luck...
what i want to do is;

split the text in richedit after every 500 or 1000 characters and save to the txt files...
i dont know if it is possible also !!!

Автор: huismori 3.12.2010, 16:22
i found something but it doesnt really do what i want !!!
how can i work with this code !!!

Цитата

var
  before, after : string;
begin
  before := Memo0.Text;
  After := WrapText(before, 500);
  Memo1.Text:=After[0];
  Memo2.Text:=After[1];
  Memo3.Text:=After[2];
end;

Автор: huismori 3.12.2010, 17:29
ok i found something else... it is doing what i want but there is a small problem with it, it is splitting the character in word... how can i make it not to split if it is in the word and jump to next space to split !!!

Цитата

procedure TForm1.Button1Click(Sender: TObject);
var
  Source, Target, target2, target3 : string;
  begin
  Source := memo1.Text;
  Target := Copy(Source, 1, 500);
  target2 := Copy(Source, 501, 500);
  target3 := Copy(Source, 1001, 500);

  memo2.Text:=target;
  memo3.Text:=target2;
  memo4.Text:=target3;
end;

Автор: huismori 8.12.2010, 10:26
can anyone help me please ?

Автор: cat512 8.12.2010, 13:04
Цитата(huismori @ 8.12.2010,  10:26)
can anyone help me please ?

you can try this
Код

WrapText(RichEdit.Lines.text, sLineBreak, [#32,{need to add the code of tab}] , 500);



Автор: huismori 8.12.2010, 15:37
Цитата(cat512 @ 8.12.2010,  13:04)
Цитата(huismori @ 8.12.2010,  10:26)
can anyone help me please ?

you can try this
Код

WrapText(RichEdit.Lines.text, sLineBreak, [#32,{need to add the code of tab}] , 500);



what do you mean with ''the code of tab'' !!!

Автор: cat512 8.12.2010, 19:39
Цитата

what do you mean with ''the code of tab'' !!!

iif you need to split some text beginning at special character like gaps (#32), crlf(#13#10), tab character(i forget the number) and etc, then you must add the number of special character into that parameter

Автор: huismori 8.12.2010, 22:24
what i want to do is to split the text in rich edit after every 500 characters and put every 500 character in different memo objects...

Автор: cat512 9.12.2010, 01:10
Цитата(huismori @ 8.12.2010,  22:24)
what i want to do is to split the text in rich edit after every 500 characters and put every 500 character in different memo objects...

It isn't difficult. 
Код

procedure TForm1.FormCreate(Sender: TObject);
const
  cDelimiter = '*#*';
var
  S: string;
  MatchPos: integer;
begin
  S := '11 11111 1111111 1 11111111 1111111';
  S := WrapText(s, cDelimiter, [' '], 10);
  repeat
    MatchPos := Pos(cDelimiter, S);
    ShowMessage(Copy(S, 1, Ifthen(MatchPos > 0,  MatchPos - 1, Length(s))));
    Delete(S, 1, Ifthen(MatchPos > 0, MatchPos + Length(cDelimiter) - 1, -1));
  until MatchPos <= 0;
end;

don't forget declare the "math" unit

Автор: huismori 9.12.2010, 09:57
thanks alot cat512
thats doing what i want... 1 more thing;
can i put splitted texts in memo objects or stringlists? not in message dialogs !!!

Автор: cat512 9.12.2010, 13:50
yes you can. It is a sample I have showed you. Of course, you can improve it

Автор: huismori 9.12.2010, 14:29
here what i tried but it didnt really do it good !!! it giveas error if there is no data in to put in memo4... error is: List index out of bounds(4) 
what am i doing wrong ??? 

Код

const
  cDelimiter = '*#*';
var
  S: string;
  MatchPos, i: integer;
  table : TStringList;
begin
  table := TStringList.Create;
  S := '11 11111 1111111 1 11111';
  S := WrapText(s, cDelimiter, [' '], 10);
  repeat
    MatchPos := Pos(cDelimiter, S);
    table.Add(Copy(S, 1, Ifthen(MatchPos > 0,  MatchPos - 1, Length(s))));
    Delete(S, 1, Ifthen(MatchPos > 0, MatchPos + Length(cDelimiter) - 1, -1));
  until MatchPos <= 0;
    for i := 0 to table.Count-1 do
     memo1.Text:= (table[0]);
     memo2.Text:= (table[1]);
     memo3.Text:= (table[2]);
     memo4.Text:= (table[3]);
end;

Автор: cat512 9.12.2010, 17:45
Who writes a cycle so???
you need to index the "table's" items by variable of cycle.
Код

    for i := 0 to table.Count-1 do
    case I of
      1: memo1.Text := Table[I];
      2: memo2.text := Table[I];
      3: memo3.text := ...
      4:{and so on};
    end;

In generally, it will be better never to use the stringlist object here. Why do you need a unnecessary variable?

Автор: huismori 9.12.2010, 17:57
i need to make limited lists for text and it is gonna be about 500 or 1000 characters and after i need to send these lists to user... so i thought it would b easier if i put them in memo objects... do u have better idea ?

Автор: cat512 9.12.2010, 19:28
I understood what you need, but I need to specify some points.
How are you going to send a text for your users? I would like that you give me more details. 

Автор: huismori 9.12.2010, 20:09
thanks alot for all your helps cat512
i managed to it for the moment...

 smile 

Автор: huismori 14.12.2010, 14:36
solved !!!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)