Readdy Write

Gelöst: conversion from void to non-scalar type String requested bei String.replace und toLowerCase

06.05.2020 (👁5630)


 

Fehlermeldung:

error: conversion from 'void' to non-scalar type 'String' requested

 

Fehlerzeile, Arduino Original-Code

Original von der Webseite Arduino.cc -> Tutorial/StringSubstring

String stringTwo = stringOne.replace("<html><head></head><body></body></html>", "Blah");

 

Debug Meldung

exit status 1

conversion from 'void' to non-scalar type 'String' requested

 

 

Lösung:

Keine Übergabe in eine zweite Variable

   stringTwo.replace("a","b");

 

 

 

 

Lösung:

Bei Replace(..) wird der Rückgabe nicht in eine zweite Variable übergeben, sondern das Ergebnis wird in die Variable selbst zurückgeschrieben

  // put your main code here, to run repeatedly:

   String stringOne = "abc";

   String stringTwo = stringOne;

   

   //ok: 

   stringTwo = stringTwo.substring(2);

   //ok:

   stringTwo.replace("a","b");

   

   //error:

   //string as result of string.replace(a,b)

   stringTwo = stringOne.replace("a","b");

 

 


0,00 €