In memo1 there is a text of this kind:

Zadacha378328328

Zadacha435455656

Zadacha7785343434

Split text by character, that is:

For example:

I specify in Edit1 - the number 4 (from which to divide the character)

I specify a separator in Edit2, for example "-"

I specify in Edit3 how many parts per line, for example 2

And the text in memo1 changes:

Zada-ch-a3-78-32-83-28

Zada-ch-a4-35-45-56-56

Zada-ch-a7-78-53-43-434 (if the number of characters is not pair, then at the end like this, all that remains).

  • Study assignments are allowed as questions only under the condition that you tried to solve them yourself before asking a question. Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote trying to solve the problem - Kromster

2 answers 2

I solved the problem in this way:

procedure TForm1.Button1Click(Sender: TObject); var i: integer; L: TStringList; s: String; begin L := TStringList.Create; L.Delimiter := Edit2.Text[1]; for i := 0 to Memo1.Lines.Count - 1 do begin L.Clear; s := Memo1.Lines[i]; L.Add(Copy(s, 1, StrToInt(Edit1.Text))); Delete(s, 1, StrToInt(Edit1.Text)); while Length(s) > StrToInt(Edit3.Text) do begin L.Add(Copy(s, 1, StrToInt(Edit3.Text))); Delete(s, 1, StrToInt(Edit3.Text)); end; L.Add(s); Memo2.Lines.Add(L.DelimitedText); end; L.Free; end; 

    Try to approach simply - iterate over the input line one character at a time and add the character (s) to the resulting line (of course there will be a service variable that stores the number of characters after the last separator).

    The i-th character of the string S will be S [i].