Jump to content

Delete(Str: String; Start, Length: Integer)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
volshba

volshba

    Newbie

  • Members
  • Pip
  • 2 posts
Hello.
can u help me.
I have a code:
procedure Tpa.Button2Click(Sender: TObject);

var

  Temp: TStringList;

  Index: Integer;

   s: Integer;

begin

     Temp:= TStringList.Create();

  try

    for Index:= 0 to FList.Count - 1 do

if  ('apple', FList[Index]) <> 0) and (Temp.IndexOf(FList[Index]) = -1)

then Temp.Add(FList[Index]);

    try

      begin

Temp.SaveToFile('fruits.txt');                      

   end;

    except

      ShowMessage('error!');

    end;

  finally

    Temp.Free();

  end;

     end;
and i need use in this button functions "Delete(Str: String; Start, Length: Integer)".
I need to remove all 'garbage' after this word.
How do I do this?
example:
'apple ererewerwer'
result:
only 'apple'

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
How are you defining the end of a word? For example, if you have 'apple ererewerwer' in string Data, then I could do:
Data := copy(Data,1,pos(' ',Data)-1);
to remove all characters starting at the space.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
volshba

volshba

    Newbie

  • Members
  • Pip
  • 2 posts
ok. but if i have 'applesdfsdfsdf' without the space?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
How are you defining "garbage"? For example, your case could return either 'apple' or 'apples' depending on whether the s is considered garbage or not.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog