Home > Back-end >  Delphi read TXT text under the specified character darting in character writing data and save
Delphi read TXT text under the specified character darting in character writing data and save

Time:09-15

Small white appearance: the big teacher more business problem description


Known '. \ memo. TXT '

Memo. TXT text file with the

[GOLON]
The original string

[gewq]
The original string

[SWWWQ]
The original string




Need under the [GOLON] written string

Each time you save all the string written before in deleted but not to delete the original string


[GOLON]
The string 1
String 2
String 3
String 4

The original string



A great god grant instruction for example study best

CodePudding user response:

 unit Unit1; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
Memo1: TMemo;
For: TButton;
Edit1: TEdit;
Memo2: TMemo;
ComboBox1: TComboBox;
Button3: TButton;
Button4: TButton;
Procedure Button1Click (Sender: TObject);
Procedure Button3Click (Sender: TObject);
Procedure Button4Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
The end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure SetText (FileName: string; The title, S: string);//function
Var MyList: TStringList;
I, j, k: integer;

Label X;

The begin
MyList:=TStringList. Create;
MyList. LoadFromFile (FileName);
For I:=0 to Mylist. Do the Count - 1
The begin
If the Trim (MyList. Strings [I])=Trim (title) then
The begin
//find the tail
J:=I;
Repeat
J:=j + 1;
Until (j=Mylist Count - 1) or (Copy (Trim (Mylist. Strings [j]), 1, 1)='[');
Showmessage (inttostr (j));
If J> (I + 1) then//delete
The begin
For k: downto I=j - 1 + 1 do
Mylist. Delete (k);
The end;
If I=Mylist.//Count - 1
add new charactersThen Mylist. Add (S)
The else Mylist. Insert (I + 1, S);
Goto X;
The end;
The end;
X:
MyList. SaveToFile (FileName);
Mylist. Free;
The end;

procedure TForm1.Button1Click(Sender: TObject);//processing
Var FileName, Title, S: a string;
The begin
FileName:='D: \ memo. TXT';
Title:=Combobox1. Text;
S:=Memo2. Text;
SetText (FileName, title, S);
Memo1. Lines. LoadFromFile (Filename);
The end;

Procedure TForm1. Button3Click (Sender: TObject);//read
Var FileName, Title, S: a string;
The begin
FileName:='D: \ memo. TXT';
Memo1. Lines. LoadFromFile (Filename);
The end;

Procedure TForm1. Button4Click (Sender: TObject);//write
Var FileName, Title, S: a string;
The begin
FileName:='D: \ memo. TXT';
Memo1. Lines. SaveToFile (Filename);
The end;

End.

CodePudding user response:



They change, they can use, you can also add a small title, such as [888]
  • Related