user28063: According to the manual:
https://www.arduino.cc/en/Reference/StringTrim
Trim strips one or more whitespaces from the beginning and the end. Does it also removes tabulators and \n ?
I have the following code which works:
 while (Serial.available()) {   // something came across the serial   
      char c = (char)Serial.read();
      Command += c;
      Command.trim();
      if (c=='\n')
         {
           Complete =true;
         }   
   if (Command.length() >0 && Complete) {

        if (Command == "LED_ON") {
               // Do stuff
        }       

Although I'm not sure that it is working because of the last if statement which says: if (Command == "LED_ON") ignores the ending \n and say ok it matched OR Command.trim() really takes off that \n.
Thank you

user10794: Whilst rchard2scout is quite right that trim will remove newlines, why not rearrange the code so it doesn't matter?
  char c = (char)Serial.read();
  if (c == '\n')
     Complete = true;
  else
     Command += c;


user27844: Yes, \n is also removed.
The source for the trim() function is in WString.cpp.
void String::trim(void)
{
    if (!buffer || len == 0) return;
    char *begin = buffer;
    while (isspace(*begin)) begin++;
    char *end = buffer + len - 1;
    while (isspace(*end) && end >= begin) end--;
    len = end + 1 - begin;
    if (begin > buffer) memcpy(buffer, begin, len);
    buffer[len] = 0;
}

We can see it uses the isspace() function, but where's that function defined? WString.cpp only #includes WString.h, so we go there.
In WString.h, we can see it includes ctype.h. Time to go to the C++ Reference, which tells us that yes, \n is a "space" according to isspace(), so it is trimmed.
(note that isspace() is affected by localization settings. I'm not sure what the localization settings are when compiling for Arduino)

28063: <p>According to the manual:</p>

<p><a href="https://www.arduino.cc/en/Reference/StringTrim" rel="nofollow">https://www.arduino.cc/en/Reference/StringTrim</a></p>

<p>Trim strips one or more whitespaces from the beginning and the end. Does it also removes tabulators and \n ?</p>

<p>I have the following code which works:</p>

<pre><code> while (Serial.available()) {   // something came across the serial   
      char c = (char)Serial.read();
      Command += c;
      Command.trim();
      if (c=='\n')
         {
           Complete =true;
         }   
   if (Command.length() &gt;0 &amp;&amp; Complete) {

        if (Command == "LED_ON") {
               // Do stuff
        }       
</code></pre>

<p>Although I'm not sure that it is working because of the last if statement which says: if (Command == "LED_ON") ignores the ending \n and say ok it matched OR Command.trim() really takes off that \n.</p>

<p>Thank you</p>
 10794: <p>Whilst rchard2scout is quite right that <code>trim</code> will remove newlines, why not rearrange the code so it doesn't matter?</p>

<pre class="lang-c++ prettyprint-override"><code>  char c = (char)Serial.read();
  if (c == '\n')
     Complete = true;
  else
     Command += c;
</code></pre>
 27844: <p>Yes, \n is also removed.</p>
<p>The source for the trim() function is in <a href="https://github.com/arduino/Arduino/blob/be9bbc3255e784108fc10a069d79a4fa8b4ca37e/hardware/arduino/avr/cores/arduino/WString.cpp#L719-L729" rel="nofollow noreferrer">WString.cpp</a>.</p>
<pre><code>void String::trim(void)
{
    if (!buffer || len == 0) return;
    char *begin = buffer;
    while (isspace(*begin)) begin++;
    char *end = buffer + len - 1;
    while (isspace(*end) &amp;&amp; end &gt;= begin) end--;
    len = end + 1 - begin;
    if (begin &gt; buffer) memcpy(buffer, begin, len);
    buffer[len] = 0;
}
</code></pre>
<p>We can see it uses the <code>isspace()</code> function, but where's that function defined? <code>WString.cpp</code> only <code>#include</code>s <code>WString.h</code>, so we go there.</p>
<p>In <code>WString.h</code>, we can see <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/WString.h#L28" rel="nofollow noreferrer">it includes <code>ctype.h</code></a>. Time to go to the <a href="http://www.cplusplus.com/reference/cctype/isspace/" rel="nofollow noreferrer">C++ Reference</a>, which tells us that yes, <code>\n</code> is a &quot;space&quot; according to isspace(), so it is trimmed.</p>
<p>(note that <code>isspace()</code> is affected by localization settings. I'm not sure what the localization settings are when compiling for Arduino)</p>
