Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Deleting in TStrings

Hi,

I have TStrings like this :

a=apple
b=orange
c=frog

Anyone can help, how can I delete an entry based on the LEFT side string?

Like this :

   function deletestring(leftkey: string; T: TStrings) : boolean;

So, I can use it like this :

   if (deletestring("b", T)) then ... it's deleted

Thanks.
0
db2trade
Asked:
db2trade
  • 2
1 Solution
 
mocartsCommented:
function deletestring(const leftkey: string; T: TStrings): boolean;
var
 idx: integer;
begin
 idx := T.indexOfName(leftKey);
 Result := (idx > -1);
 if Result then
  T.Delete(idx);
end;

wbr, mo.
0
 
kretzschmarCommented:
maybe this ?

function DeleteString(leftkey: string; T: TStrings) : boolean;
var i : integer;
begin
  i := t.indexOfName(leftKey);
  if i > -1 then
    t.Delete(i);
  result := i > -1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if DeleteString(edit1.text, listbox1.items) then
    ShowMessage('String deleted')
  else
    ShowMessage('No such String available');
end;

meikl ;-)
0
 
kretzschmarCommented:
puu, too late :-(
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now