how to println double quotation mark " using println

Hello,

I am trying to use println to print a double quotation mark (") onto the debug output screen.  It should work on the watch, but it isn't working properly on the debug output in vsCode - it prints out the escape character too, so rather than just print " it prints \" , which is not what I want.

This is the code I am using.  Any idea what the problem is?  Does it happen for you as well?

        System.println ("test double quotation here -> ' \" ' "));
        // output:test double quotation here -> ' \" '
  • I think this is a bug in System.println and/or the logger. It doesn't show up in the sim and (as you pointed out), probably not on the watch, either.

    I can make the same thing happen without even using the "\" character in code, which proves that it's the logger which is adding "\" to quote characters.

    e.g. simple data field:

    // ...
        public function compute(info as Info) as Numeric or Duration or String or Null {
            System.println(g_quote);
            return g_quote;
        }
    }
    var g_quote = '"'.toString();

  • Sorry, forgot to post the memory view which shows that g_quote is indeed equal to ".

  • println() is really just a debugging thing.  It's not something I'd use as a feature in a production app. as the user would need to manually create the .txt log file, with the name based on the 8 character store name for the prg file - not something simple to find.

    And you also have the log file limit where the txt file becomes a ..bak file, and the old bak file data is lost.

    System.println ("test double quotation here -> ' \" ' "));

    displays exacting what the string is with no modifications.  You'll find other things println() doesn't handle.  Like some UFT-8 characters

    consider

    var degree="°";
    With println() it's displayed incorrectly
    With drawText(), degree shows correctly (if the font has the character)  as does "test double quotation here -> ' \" ' "
     

  • println() is really just a debugging thing.  It's not something I'd use as a feature in a production app. as the user would need to manually create the .txt log file, with the name based on the 8 character store name for the prg file - not something simple to find.

    You type that as if everyone is this thread doesn’t already understand that.

    System.println ("test double quotation here -> ' \" ' "));

    displays exacting what the string is with no modifications.

    Take a look at the code and screenshot in my previous reply a bit more closely.

    var g_quote = '"'.toString();
    System.println(g_quote);

    This literally prints:
    \"

    Note the lack of a \ character in the code. I also don’t think you understand how escaping of special characters generally works in strings if you think the string in your example literally contains a \ character. (Hint: assign that string to a global variable and look at it in the simulator’s memory view. Also, print out the string length.)

  • You type that as if everyone is this thread doesn’t already understand that.

    I'm betting a number of new devs don't know that and they are reading this thread.  It's called "context" as to why it's mainly a debug thing..  

  • You type that as if everyone is this thread doesn’t already understand that.

    If the OP understood that, it's a bit odd that he cares so much about getting quotes out of it.

  • Thanks for all the replies everyone; they were useful contextually, despite not resulting in the exact answer I was looking for.  I see that it happens for others as well.  It's not ideal, but I can work with it. 

    Some more context for my original question follows--  I am developing an algorithm which produces CSV data to be imported into google maps, and from what I can tell thus far, double quotation marks are included before and after the WKT data.  The app and algorithm I am developing it for is in the beta stage, therefore I am outputting to the debug window in order to make changes to my algorithm.  

    In order to copy and paste the data into a properly formatted CSV file I will just have to CTRL+F or CTRL+H to switch out \" with ".  Earlier I used XML format and it wasn't a problem but then google maps was giving me problems reading the XML formatted data, so I have switched over to CSV.

    Sample file:

    WKT,name,description
    "POINT (longitude1_Double, latitude1_Double 0.0)",point one
    "POINT (longitude2_Double, latitude2_Double 0.0)",point two

    thanks again

    -----------------

    And, in retrospect, I think that this debugger error didn't exist some months ago, because it printed out the double quotation mark fine when I was importing the XML data into google maps... and the first line in my XML file was coded this way:

    System.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"htp://www.opengis.net/kml/2.2\">\n <Document>");
    // output: 
    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="htp://www.opengis.net/kml/2.2">
    // htp text used to prevent automatic link from being created
  • I think it's a fair ask, that the println() function be able to print out double quotation marks into debug output, without having them prefixed with a backslash, like I would expect from the production functionality of println(), and in other versions of the C and other programming languages.  I added a ticket for it here https://forums.garmin.com/developer/connect-iq/i/bug-reports/debugger-in-vscode-incorrectly-prints-escape-character-for-double-quotation-mark 

    As an alternative to using the (\) escape character, is there any OTHER way to print out a double quotations mark ("), by itself and not prefixed by any character, into the debug output field?

    Thanks for your contributions as usual, to all who have replied to me here.  It's always helpful to hear what you have to say.