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.
LVL 1
db2tradeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.