I need to delete text between characters (two options). Text of this type:

TEST """111111> TEST1 TEST """222222>> TEST2 TEST """333>>> TEST3 TEST "444444>>> TEST4 TEST ""5555>>> TEST5 

To get the output:

Option 1 (Only text and symbols leave):

 TEST """> TEST1 TEST """>> TEST2 TEST """>>> TEST3 TEST ">>> TEST4 TEST "">>> TEST5 

Option 2 (Inclusive with characters):

 TEST TEST1 TEST TEST2 TEST TEST3 TEST TEST4 TEST TEST4 

Specification: It is meant to delete the text between:

 """ ΠΈ этим > """ ΠΈ этим >> """ ΠΈ этим >>> " ΠΈ этим >>> "" ΠΈ этим >>> 

Option 1 - leave characters and delete only text between characters.

Option 2 - delete characters and text that is between characters.

After processing the code that I have here:

// In edit I specify between what and with what to delete

 Len := Length(S); Pos1 := 0; for P := Len downto 1 do begin if (S[P] = edit3.text) and (Pos1 = 0) then begin Pos1 := P; end; if (S[P] = edit2.text) and (Pos1 <> 0) then begin Delete(S, P, Pos1 - P + 1); Pos1 := 0; end; 

I get this result (That is, some of the characters remain):

 TEST "" TEST1 TEST "" TEST2 TEST "" TEST3 TEST TEST4 TEST " TEST5 
  • Here with the terminology of the problem. Probably the task sounds: Option 1. Delete all numbers. Option 2. leave only letters and spaces - JaponDemon
  • @JaponDemon, I gave an example of text - which can be between characters. And the task is set correctly. - Tatiana
  • one
    TEST T>ES_T2 TEST4 what needs to be removed from here? Formulate removal requirements - Anton Shchyrov
  • one
    You wrote what you need, but you forgot to write a question. What you can't do, how / how can we help you in the ruSO format? - Kromster
  • one
    Do you remember about regular expressions that links were given? Now, if you understood them (regular expressions) This question would not be - JVic

1 answer 1

The question is solved in this way.

 // поиск ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ вхоТдСния символа function LastSymbolPos(const C: Char; const s: string): integer; var i: DWORD; begin Result:= 0; for i:= Length(s) downto 1 do if s[i] = C then begin Result:= i; Break; end; end; // поиск послСднСго вхоТдСния символа function FirstSymbolPos(const C: Char; const s: string): integer; var i: DWORD; begin Result:= 0; for i:= 1 to Length(s) do if s[i] = C then begin Result:= i; Break; end; end; procedure TForm2.Button1Click(Sender: TObject); var i,a,b: byte; s: string; begin Memo2.Lines.Add('Π’Π°Ρ€ΠΈΠ°Π½Ρ‚ 1'); for i:= 0 to Pred(Memo1.Lines.Count) do begin s:= Memo1.Lines[i]; a:= LastSymbolPos('"',s)+1; b:= FirstSymbolPos('>',s); Delete(s,a,ba); Memo2.Lines.Add(s); end; end; procedure TForm2.Button2Click(Sender: TObject); var i,a,b: byte; s: string; begin Memo2.Lines.Add('Π’Π°Ρ€ΠΈΠ°Π½Ρ‚ 2'); for i:= 0 to Pred(Memo1.Lines.Count) do begin s:= Memo1.Lines[i]; a:= FirstSymbolPos('"',s); b:= LastSymbolPos('>',s)+1; Delete(s,a,ba); Memo2.Lines.Add(s); end; end; 
  • one
    FirstSymbolPos can be replaced with Pos() standard - Anton Shchyrov
  • @Anton Shchyrov, Made, always nice when in my topics - people help and prompt. - Tatiana
  • one
    I do not know how in XE, but in XE3 you can write like this s.IndexOf('"') , s.LastIndexOf('>') - Anton Shchyrov
  • one
    @AntonShchyrov in XE2 is still impossible unfortunately. - Kromster
  • one
    And there is also LastDelimeter and StrRScan , but my bike is always more fun, I do that sometimes :) - Alekcvp