user32455: I am trying to execute some webbased calls, but my string keep "disappearing", and I am highly confused about why.
I can println a string directly, but if I have it in a variable, it will disappear :I
I tried googling around, but could not find a reason for it. Is it because of the curly brackets ? Is it a memory issue ?
I feel I really can't code on and juggle web calls, if I can't even handle regular string commands..
Code:
Serial.println(" - CONSOLE/STRING WEIRDNESS - ");
String message = "Testing time {0}";
Serial.println(message);
Serial.println(String(message));
Serial.println("Testing time {0}");
Serial.println(message.substring(3,6));

Response:
- CONSOLE/STRING WEIRDNESS - 
(nothing)
(nothing)
Testing time {0}
(nothing)


Update
This seems to happen whenever there is a number inside a string, it even happends with a simple string like this:
Code:
Serial.println(" - CONSOLE/STRING WEIRDNESS - ");
String message = "Testing time here is a number 0";
Serial.println(message);
Serial.println(String(message));
Serial.println("Testing time here is a number 0");
Serial.println(message.substring(3,6));

Response:
- CONSOLE/STRING WEIRDNESS - 
(nothing)
(nothing)
Testing time here is a number 0
(nothing)


user31105: The {0} denotes an extra parameter (which you want to print), it seems you just want to print the string without any variable 'value' so you can remove the {0}.
I'm not so familiar with using {0} in C++, but in C# {0} means argument number 0 (after the initial string), since this argument is not given, probably an empty string is created ... it would be more intuitive if the compiler give an error or warning (maybe it gives a warning and you can check for it).
Also converting a string to String() does not do anything but I think it was just for debugging/checking purposes.
Also in Arduino to save SRAM space, normally it is wise to add before each string, the F function like:
Serial.println(F("Some string to print"));

This will create a memory in Flash and will not be copied to SRAM which is normally quite scarce.
To print out arguments you can simply use multiple print commands (which does not add a new line) and the last part of the line with println, like:
Serial.print(F("Test time: ");
Serial.println(test_time);


32455: <p>I am trying to execute some webbased calls, but my string keep "disappearing", and I am highly confused about why.</p>

<p>I can println a string directly, but if I have it in a variable, it will disappear :I</p>

<p>I tried googling around, but could not find a reason for it. Is it because of the curly brackets ? Is it a memory issue ?</p>

<p>I feel I really can't code on and juggle web calls, if I can't even handle regular string commands..</p>

<p><strong>Code:</strong></p>

<pre><code>Serial.println(" - CONSOLE/STRING WEIRDNESS - ");
String message = "Testing time {0}";
Serial.println(message);
Serial.println(String(message));
Serial.println("Testing time {0}");
Serial.println(message.substring(3,6));
</code></pre>

<p><strong>Response:</strong></p>

<pre><code>- CONSOLE/STRING WEIRDNESS - 
(nothing)
(nothing)
Testing time {0}
(nothing)
</code></pre>

<p><a href="https://i.stack.imgur.com/Fw3nP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fw3nP.jpg" alt="The code and the debugger"></a></p>

<p><strong>Update</strong></p>

<p>This seems to happen whenever there is a number inside a string, it even happends with a simple string like this:</p>

<p><strong>Code:</strong></p>

<pre><code>Serial.println(" - CONSOLE/STRING WEIRDNESS - ");
String message = "Testing time here is a number 0";
Serial.println(message);
Serial.println(String(message));
Serial.println("Testing time here is a number 0");
Serial.println(message.substring(3,6));
</code></pre>

<p><strong>Response:</strong></p>

<pre><code>- CONSOLE/STRING WEIRDNESS - 
(nothing)
(nothing)
Testing time here is a number 0
(nothing)
</code></pre>
 31105: <p>The {0} denotes an extra parameter (which you want to print), it seems you just want to print the string without any variable 'value' so you can remove the {0}.</p>

<p>I'm not so familiar with using {0} in C++, but in C# {0} means argument number 0 (after the initial string), since this argument is not given, probably an empty string is created ... it would be more intuitive if the compiler give an error or warning (maybe it gives a warning and you can check for it).</p>

<p>Also converting a string to String() does not do anything but I think it was just for debugging/checking purposes.</p>

<p>Also in Arduino to save SRAM space, normally it is wise to add before each string, the F function like:</p>

<pre><code>Serial.println(F("Some string to print"));
</code></pre>

<p>This will create a memory in Flash and will not be copied to SRAM which is normally quite scarce.</p>

<p>To print out arguments you can simply use multiple print commands (which does not add a new line) and the last part of the line with println, like:</p>

<pre><code>Serial.print(F("Test time: ");
Serial.println(test_time);
</code></pre>
