How to test a string variable for a trailing aprostrophe?

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

LVL 1
IT79637Asked:
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.

Emmanuel PASQUIERFreelance Project ManagerCommented:
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

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
Geert GOracle dbaCommented:
you can also use the ascii equivalent : #39 = single quote


if RightStr(strLine,1) = #39 then
  strLine := LeftStr(strLine, Length(strLine)-1);
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
that is much less readable, for just one less key pressed
Geert, that is not the best advice you gave here :op
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Geert GOracle dbaCommented:
... ugh ... what you expect me to say ?
merry christmas is too soon  ...
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
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
0
mlmccCommented:
If you are trying to eliminate the ' you could also use the AnsiReplaceStr

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

mlmcc
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.