How to split a long line code into to line in the code

Hello, I know it's a stupid question, but i can't remind me how to do this....

In my code i have a long line, i would like to continous tho line under the first one, I con't remind me which character i must put at th end of the first part of the line (and maybe at the begin of the second part)

Some one can help me ?

If you're splitting code, there's nothing special to do - break the line wherever whitespace is appropriate. If you're trying to split strings, you can use \ or just close the string with " and reopen in on the new line with another one.

1 Like

Many thanks for the quick response... And sorry, that was a stupid question ;) it's true....

There is an exception to the rule that you can split the line anywhere where white space is allowed without using a special character. Preprocessor directives (i.e. lines starting with # and a preprocessor keyword) - in particular, #define - are terminated by end-of line. In this case you need to end the line in the backslash character \ and the next line will be concatenated with it.

dc42: There is an exception to the rule

There's another exception that you can't split a string literal in the middle. however, two successive string literals are concatenated, so you can write it like so:

  Serial.println("foo"
      "bar");  // will print "foobar"

jwatte: There's another exception that you can't split a string literal in the middle. however, two successive string literals are concatenated, so you can write it like so:

Believe it or not, my first version of that post said there were two exceptions and made the same point as you do about concantaion of string literals. Then I realised that spaces in a string literal are not "white space" and therefore splitting a string doesn't come under the rule. So I edited that bit out of the post.

1 Like

I believe it :-)

wildbill: If you're splitting code, there's nothing special to do - break the line wherever whitespace is appropriate. If you're trying to split strings, you can use \ or just close the string with " and reopen in on the new line with another one.

I've found, using Arduino 1.8.12 in macOS 10.14.6, that any whitespace at the beginning of the next line after the \ character is inserted into the string:

Serial.print("Foo\
                  bar");

Gives the output

Foo                bar