Recent

Author Topic: How insert apostrophe in string?  (Read 23494 times)

lublinkermi

  • New Member
  • *
  • Posts: 46
How insert apostrophe in string?
« on: August 01, 2010, 02:05:27 pm »
Hi, I need string like this:

osql -S server -d database -E  -Q "BACKUP DATABASE database TO DISK ='c:\database' FORMAT";

If I wrote like Delphi:

osql -S server -d database -E  -Q "BACKUP DATABASE database TO DISK =''c:\database'' FORMAT";

'' - is a 2 aphostrophe
I see:
Fatal: Syntax error, ";" expected but "identifier C" found

How I can insert apostrophe in string in Lazarus?




cjhs22a

  • Newbie
  • Posts: 6
Re: How insert apostrophe in string?
« Reply #1 on: August 01, 2010, 03:03:02 pm »
use the QuotedStr function

'BACKUP DATABASE database TO DISK =' + QuotedStr('c:\database') + ' FORMAT'

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12718
  • FPC developer.
Re: How insert apostrophe in string?
« Reply #2 on: August 01, 2010, 03:06:16 pm »

How I can insert apostrophe in string in Lazarus?


It works for me perfectly.  Could you provide an actually compilable example?

fredycc

  • Sr. Member
  • ****
  • Posts: 264
Re: How insert apostrophe in string?
« Reply #3 on: August 01, 2010, 06:29:07 pm »
Try using format function; I using it for any query:

For Example:
Quote
Format('INSERT INTO %s.dbo.%s ( %s ) VALUES ( ',[ZConnection2.Database,ComboBox2.Text,txFields])

More info:
http://www.delphibasics.co.uk/RTL.asp?Name=Format

Regards.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How insert apostrophe in string?
« Reply #4 on: August 01, 2010, 06:58:19 pm »
If you write '''' (2 apostrophes inside apostrophes), you will have ' (1 apostrophe). So you could write '''Hello''' to have 'Hello'.
« Last Edit: August 01, 2010, 07:42:15 pm by typo »

lublinkermi

  • New Member
  • *
  • Posts: 46
Re: How insert apostrophe in string?
« Reply #5 on: August 04, 2010, 07:37:50 pm »
I rebuild Lazarus and all works, thanks  ;)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: How insert apostrophe in string?
« Reply #6 on: September 09, 2015, 12:30:29 pm »
I add apostrophe as a char:
'...' +#39+ '...'
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

 

TinyPortal © 2005-2018