3
\$\begingroup\$

I try to run this example code on my Arduino, but since Arduino IDE version 1.0 it doesn't work no more. The example is mainly copied and stripped down from this example.

void setup() {
 Serial.begin(9600);
}
void loop() {
 // toUpperCase() changes all letters to upper case:
 String stringOne = "test";
 Serial.println(stringOne);
 stringOne = (stringOne.toUpperCase());
 Serial.println(stringOne);
 // do nothing while true:
 while(true);
}

Error message:

StringCaseChanges.cpp: In function ‘void loop()’: StringCaseChanges.cpp:12:39: error: no match for ‘operator=’ in ‘stringOne = stringOne.String::toUpperCase()’ /usr/share/arduino/hardware/arduino/cores/arduino/WString.h:83:11: note: candidates are: String& String::operator=(const String&) /usr/share/arduino/hardware/arduino/cores/arduino/WString.h:84:11: note: String& String::operator=(const char*)

On the help page one can see that:

As of 1.0, toUpperCase() modifies the string in place rather than returning a new one.

However I don't see the reason why the example code doesn't compile.

Can you help me?

Thank you!

//EDIT

OK, this one works: void setup() { Serial.begin(9600); }

void loop() {
 // toUpperCase() changes all letters to upper case:
 String stringOne = "test";
 Serial.println(stringOne);
 stringOne.toUpperCase();
 Serial.println(stringOne);
 // do nothing while true:
 while(true);
}

However, the help page should be changed!

Majenko
56.7k10 gold badges111 silver badges195 bronze badges
asked Dec 11, 2011 at 11:58
\$\endgroup\$
3
  • 3
    \$\begingroup\$ You should put your solution in as an answer. \$\endgroup\$ Commented Dec 11, 2011 at 14:15
  • 5
    \$\begingroup\$ Yes... Please roll back your edit and then place an answer to your question. We will be able to up vote the answer and you can even accept your own answer. \$\endgroup\$ Commented Dec 11, 2011 at 16:03
  • 1
    \$\begingroup\$ The help page looks fine; it's the linked tutorial example that needs to be updated. \$\endgroup\$ Commented Dec 11, 2011 at 17:21

1 Answer 1

5
+50
\$\begingroup\$

As of 1.0, toUpperCase() modifies the string in place rather than returning a new one.

However I don't see the reason why the example code doesn't compile.

The thing to note on the help page is that it says "Returns: none". Since the method invocation returns nothing, and you can't assign "nothing" to a string, you get that (somewhat unhelpful) error.

The solution is to simply omit the assignment, as the method invocation itself has done everything you hoped to do, and end up with this line of code:

stringOne.toUpperCase();

answered Dec 18, 2011 at 18:38
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.