user83052: I want to replace the ":"(colon) in the MAC address with no char (remove the ":").
But I can't find any good solution.
String.replace(), can't replace with (void).
Note: String.replace(':',(char)0) //also doesn't work
String.remove() is ugly and requires that you know exactly where each iteration is (indexOf()), and this method doesn't return anything, it updates the string directly so you have to call : String.remove() for each occurence.
and String.substring() has most of the same problems as remove, except that it does return the substring, so you can do: String.substring(i,l).substring(i2,l)...
#include <WiFi.h>
String MAC;
char ssid[] = "WiFi SSID"
char psw[] = "WiFi PSW"
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin(ssid,psw);
  MAC = WiFi.macAddress();
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println("MAC Address unformatted")
  Serial.println(MAC);
  String MAC_f = MAC.replace(':', ' ');
  // Now print the MAC without the ":"
  Serial.println(MAC_f);
  // This replaces the ':' with a space.  I want to replace(remove) the ':' with no char
  // Looking for an elegant, simple, 1 liner to accomplish this.
  
  /* This looks horrible */
  MAC_f = MAC.substring(0,2)+MAC.substring(3, 5)+MAC.substring(6, 8)+MAC.substring(9, 11)+MAC.substring(12, 14)+MAC.substring(15, 17);
  /* .remove also looks terrible */
  MAC_f = MAC;
  MAC_f.remove(2,1);
  MAC_f.remove(2,1);
  // ...
  
}


user52961: Don´t use String() manipulations inside loop(). It causes heap fragmentation and program failure. Use a char array instead:
char MAC[18] = "01:23:45:67:89:AB"; // including terminating zero

for (int src = 0, dst = 0; src < sizeof(MAC); src++)
   if (MAC[src] != ':') MAC[dst++] = MAC[src];


user7508: As stated by Mat, the empty string in C++ is "". This works:
MAC_f = MAC;
MAC_f.replace(":", "");

That being said, I concur with SBF's answer: String object are not
friendly with the Arduino's memory. SBF's solution is better than
String::replace().

83052: <p>I want to replace the &quot;:&quot;(colon) in the MAC address with no char (remove the &quot;:&quot;).</p>
<p>But I can't find any good solution.</p>
<p>String.replace(), can't replace with (void).</p>
<p><strong>Note: String.replace(':',(char)0)</strong> <em>//also doesn't work</em></p>
<p>String.remove() is ugly and requires that you know exactly where each iteration is (indexOf()), and this method doesn't return anything, it updates the string directly so you have to call : String.remove() for each occurence.</p>
<p>and String.substring() has most of the same problems as remove, except that it does return the substring, so you can do: String.substring(i,l).substring(i2,l)...</p>
<pre><code>#include &lt;WiFi.h&gt;
String MAC;
char ssid[] = &quot;WiFi SSID&quot;
char psw[] = &quot;WiFi PSW&quot;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin(ssid,psw);
  MAC = WiFi.macAddress();
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(&quot;MAC Address unformatted&quot;)
  Serial.println(MAC);
  String MAC_f = MAC.replace(':', ' ');
  // Now print the MAC without the &quot;:&quot;
  Serial.println(MAC_f);
  // This replaces the ':' with a space.  I want to replace(remove) the ':' with no char
  // Looking for an elegant, simple, 1 liner to accomplish this.
  
  /* This looks horrible */
  MAC_f = MAC.substring(0,2)+MAC.substring(3, 5)+MAC.substring(6, 8)+MAC.substring(9, 11)+MAC.substring(12, 14)+MAC.substring(15, 17);
  /* .remove also looks terrible */
  MAC_f = MAC;
  MAC_f.remove(2,1);
  MAC_f.remove(2,1);
  // ...
  
}
</code></pre>
 52961: <p>Don´t use <code>String()</code> manipulations inside <code>loop()</code>. It causes heap fragmentation and program failure. Use a char array instead:</p>
<pre><code>char MAC[18] = &quot;01:23:45:67:89:AB&quot;; // including terminating zero

for (int src = 0, dst = 0; src &lt; sizeof(MAC); src++)
   if (MAC[src] != ':') MAC[dst++] = MAC[src];
</code></pre>
 7508: <p>As stated by Mat, the empty string in C++ is <code>&quot;&quot;</code>. This works:</p>
<pre class="lang-cpp prettyprint-override"><code>MAC_f = MAC;
MAC_f.replace(&quot;:&quot;, &quot;&quot;);
</code></pre>
<p>That being said, I concur with SBF's answer: <code>String</code> object are not
friendly with the Arduino's memory. SBF's solution is better than
<code>String::replace()</code>.</p>
