Recent

Author Topic: QuotedStr  (Read 263 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 397
QuotedStr
« on: May 20, 2026, 12:53:28 am »
Code: Pascal  [Select][+][-]
  1. str := '1';
  2. str := QuotedStr(str);
  3.  
copy from debug --> str = '''1'''

I guess I would expect str = ''1''

?
lazarus 3.2-fpc-3.2.2-win32/win64

dsiders

  • Hero Member
  • *****
  • Posts: 1635
Re: QuotedStr
« Reply #1 on: May 20, 2026, 01:05:33 am »
Code: Pascal  [Select][+][-]
  1. str := '1';
  2. str := QuotedStr(str);
  3.  
copy from debug --> str = '''1'''

I guess I would expect str = ''1''

?

Not according to the docs. https://lazarus-ccr.sourceforge.io/docs/rtl/sysutils/quotedstr.html

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 397
Re: QuotedStr
« Reply #2 on: May 20, 2026, 01:07:08 am »
Code: Pascal  [Select][+][-]
  1. str := '1';
  2. str := QuotedStr(str);
  3.  
copy from debug --> str = '''1'''

I guess I would expect str = ''1''

?

Not according to the docs. https://lazarus-ccr.sourceforge.io/docs/rtl/sysutils/quotedstr.html


quote from there
"QuotedStr returns the string S, quoted with single quotes. This means that S is enclosed in single quotes"
If single quote is ' ?
lazarus 3.2-fpc-3.2.2-win32/win64

Retrofoxed

  • Guest
Re: QuotedStr
« Reply #3 on: May 20, 2026, 01:18:56 am »
QuotedStr adds two single quotes and the debug copy function adds two double quotes, so you have '"..."'

jamie

  • Hero Member
  • *****
  • Posts: 7774
Re: QuotedStr
« Reply #4 on: May 20, 2026, 01:23:48 am »
Code: Pascal  [Select][+][-]
  1.  
  2. Str := Str.Quotedstring('"');
  3.  

Jamie
The only true wisdom is knowing you know nothing

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 397
Re: QuotedStr
« Reply #5 on: May 20, 2026, 12:02:06 pm »
ShowMessage displays it as it is, correct, as I read in some other thread and tested.  Unfortunately the message is cut off and not displayed in entire length.
Solution to that, to be tested .... https://forum.lazarus.freepascal.org/index.php?topic=36586.0
lazarus 3.2-fpc-3.2.2-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13583
Re: QuotedStr
« Reply #6 on: May 20, 2026, 12:52:30 pm »
Code: Pascal  [Select][+][-]
  1. str := '1';
  2. str := QuotedStr(str);
  3.  
copy from debug --> str = '''1'''
1st line:
str is a string. The value of the string variable must be enclosed by single quotes in the source code. And that's also the way the debugger displays it: '1'. But when you do a WriteLn the quotes are not displayed: WriteLn(str) --> 1. A special case is a string which already contains a single quote character: to avoid confusion with the string-identifying quotes this character then is doubled. Example: WriteLn('It''s magic') ---> It's magic.

2nd line:
QuotedStr(str) -> the function Quotedstr has the purpose to enclose the result string in single quotes (but only when the string does not begin/end with a quote already). Therefore the result of QuotedStr('1') is displayed by the debugger as '''1''': the first and last quotes are the leading and trailing quotes identifying the output as a string; the remaining quotes are the quotes added by the QuotedStr function - they are doubled because they are inside the string.

If you want to have double quotes around the input string you can use the function AnsiQuotedStr which allows a second parameter for the quoting character:
str := '1' --> AnsiQuotedStr('1', '"') --> '"1"' in the debugger, or "1" in WriteLn.

 

TinyPortal © 2005-2018