Delphi/Lazarus: Using Apostrophes ' in String
Question by Guest | 2017-02-26 at 12:43
I would like to use the apostrophe character within a string. Unfortunately, this is not possible either in Delphi or Lazarus. Every time I try to do so, the compiler only returns an error message of the type "Fatal: Syntax error ; expected but identifier found".
Interestingly, it is working like a charm using double quotes ". However, I would rather use a single quote respectively apostrophe. Is there any possibility?
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
HTML5: Upload Images with Client Side Resize
Tutorial | 9 Comments
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
Delphi/Lazarus: Display current Date and Time
Tip | 0 Comments
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
jQuery: Send HTML5 Canvas to Server via Ajax
Tutorial | 0 Comments
Create URL for Website from Title of Page
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
When defining a string, the string is separated with an apostrophe on both sides, for example s := 'abc'. If you are now using an apostrophe within the string, the compiler only sees this delimiter character and things that your string ends at this place. So, the compiler complains about anything coming thereafter.
Solution: You have to double each apostrophe that is part of your string within your string. Here is an example:
This string would be interpreted as ab'cd.
Alternatively, you can also use #39 instead of the apostrophe character:
This example, the first two rows would both result in the string 'abc' while the third line is ab'cd.
2017-02-26 at 21:20