How to test a string variable for a trailing aprostrophe?

IT79637
IT79637 used Ask the Experts™
on
HI,
I'm using D7 Ent on a Win XP Pro SP3 box.

var
   strLine : string;
begin
  strLine = " abcde' "  -->> there is a leading and trailing space for visual clarity only.  The string is 6 characters long.

I want to remove the trailing apostrophe.  How do I test for it?


if RightStr(strLine,1) = ??? then
  strLine := LeftStr(strLine, Length(strLine)-1;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance Project Manager
Top Expert 2010
Commented:
you have to double the apostrophe to specify an apostrophe in a string constant, between 2 apostrophe. So that means 4 for the apostrophe character alone

if RightStr(strLine,1) = '''' then
  strLine := LeftStr(strLine, Length(strLine)-1;

Open in new window

Geert GOracle dba
Top Expert 2009

Commented:
you can also use the ascii equivalent : #39 = single quote


if RightStr(strLine,1) = #39 then
  strLine := LeftStr(strLine, Length(strLine)-1);
Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
that is much less readable, for just one less key pressed
Geert, that is not the best advice you gave here :op
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Geert GOracle dba
Top Expert 2009

Commented:
... ugh ... what you expect me to say ?
merry christmas is too soon  ...
Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
I couldn't help the small tease, and didn't expect you to say anything, as it is obvious you have given greater solutions. I don't say mine on this question is far better, the question wasn't a big challenge anyway. My point is that readability of code IS something that must be taken into account when one write some code. Even a seasoned Delphi programmer might not recognize immediately that #39 = '

well, one does not know if the occasion will rise again before it is time, so I say it now :
Merry Christmas and Happy New Year, Geert ! Sincerely
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
If you are trying to eliminate the ' you could also use the AnsiReplaceStr

strLine := AnsiReplaceStr(strLine, '''','');

mlmcc

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial