Jump to content
Registration disabled at the moment Read more... ×
Henry Olive

Delete First & Last Character

Recommended Posts

Good Day

 

Str := 'Abc' or could be Abc

First,  I want check if first char = ' then i want to delete it

Second  I want check if Last char = ' then i also want to delete it

that is,  if Str='Abc' then the result should be Abc 

if Str = Abc then i dont need to do anything

 

Thank You

 

Share this post


Link to post

There is a lot of information and documentation available about string handling in Delphi. Here are two quick references:

 

http://www.delphibasics.co.uk/ByFunction.php?Main=Strings

https://www.thoughtco.com/string-handling-routines-delphi-programming-4092534

 

And here is a very basic solution to your request. Your actual purpose may be different from your description, but this code does what you asked:

 

  var str := '''abc''';
  WriteLn(str);
  if str[1] = '''' then
    Delete(str, 1, 1);
  var last := Length(str);
  if str[last] = '''' then
    Delete(str, last, 1);
  WriteLn(str);
  ReadLn;

 

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×