This is kind of a short question. All I want to know is, if I can define a string using single quotation marks ('), instead of the regular ones("). I want to use it in a function like this: print('Hello world');

I unfortunately do not have an Arduino nearby so I cannot test it myself.

  • 3
  • 1
    Could you please explain what you want to achieve rather than your likely misguided idea about how to achieve it (i.e. removing quotes)? Jan 26 '17 at 15:29
  • I am making an extensions for a program that requires Arduino code inside the program, but if I write the quotation marks, the debugger reports an error, because there are quotation marks inside quotation marks.
    – user29519
    Jan 26 '17 at 15:35
  • Then you need to update your extension to properly escape the arduino code so that reserved/special characters in the code are not interpreted by the non-arduino debugger. How to do that depends greatly on the program you are extending, which you have not named. Jan 26 '17 at 15:38
  • 1
    It's a bit unclear to me what you're trying to do, but perhaps just escaping the "s will achieve what you want. In C, the way to escape something is with a \, so for example char myString[] ="\"\""; would give you a string containing two "s.
    – Mark Smith
    Jan 26 '17 at 15:57

No, you can't. 'x' defines a single character or integer (note: 'ab' is a two-byte single value [integer] made up from the ASCII values of both characters).

To include " within a string you have two options:

  1. Escape the " with \, as in: char foo[] = "He said \"Hello there\".";
  2. Use "raw strings" if the compiler is configured to support it: char foo[] = R"(He said "Hello there".)";

Option 1 is the most portable since it doesn't require compiler support for modern C++ standards. However it's the hardest to read, especially when you get lots of escapes in the same string.

You can make it more readable by defining QUOTE:

#define QUOTE "\""

char foo[] = "He said " QUOTE "Hello there" QUOTE ".";

No, you cannot. This rules comes from the basic C++ syntax on which the Arduino platform is built.

  • Is there a way to define it without the qoutation marks?
    – user29519
    Jan 26 '17 at 15:27
  • 1
    Only very convoluted ways. Jan 26 '17 at 15:28
  • Actually, C++ raw string literals are easy to use (ref 1, 2); the only convoluted bit is adding a -std=c++11 or -std=c++0x switch to IDE compiler options. Jan 26 '17 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.