Good day. It is necessary to check whether the line begins with the words "Work in the Internet?" , if yes, then the first 3 words should be removed from the line, i.e., it is necessary to remove this phrase “work in the Internet”. So far I have solved the second part of the problem. I.e deleting all the characters before the "?"

procedure TForm1.Button3Click(Sender: TObject); var s , n , text: String; position: Integer; begin text:=Edit1.Text; position := pos('?', Edit1.Text); If position <> 0 then S := copy(Edit1.Text, position, length(Edit1.Text) - position + 1); end; 

But here's how to check whether the line begins with the words "Work in the Internet?" or is there another question I do not think ..

    2 answers 2

     unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Edit1: TEdit; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure DeleteSome(var s: string; some: string); var k: integer; begin k:=pos(some,s); if k>0 then delete(s,k,length(some)); end; procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items.Add(Edit1.Text); end; procedure TForm1.Button2Click(Sender: TObject); var find:string; s:string; i:integer; begin find:='Работа в интернет'; // Идем в цикле по всему списку For i:=0 to ListBox1.Items.Count-1 do // Ищем совпадение по фразе 'Работа в интернет' If Pos(find, ListBox1.Items.Text)<>0 Then Begin // Загружаем текст из списка в string s:=Listbox1.Items.Text; // Удаляем нужный текст из string DeleteSome(s,find); // Загружаем текст обратно в список Listbox1.Items.Text:=s; end; end; end. 

    If the point is how to check the beginning of the line, then StrUtils unit is AnsiStartsStr - http://www.delphisources.ru/pages/faq/faq_delphi_basics/AnsiStartsStr.php.html

    • thank you, it works! - stud
     k := Pos(find, ListBox1.Items.Text); if k = 1 then //совпадение с первого символа begin Listbox1.Items.Text := Copy(Listbox1.Items.Text, k + Length(find), Length(Listbox1.Items.Text)); end; 

    There is no need to look 2 times in the line the same thing. And you can do without a temporary variable. You can add -Length(find) to the number of characters to copy, but not necessarily. It will be copied as many characters as specified, or until the line ends.