boylesg
November 28, 2015, 11:59am
1
I know it is not possible to do a Serial.print(str), where str is a string obect, and get sensible output in the Serial monitor.
I tried this:
//for (int nI = 0; nI < strData.length(); nI++)
// Serial.print(strData[nI]);
//Serial.println("");
but it does not seem to work either.
So as there any other round about way to Serial.print a string object?
system
November 28, 2015, 2:55pm
2
I know it is not possible to do a Serial.print(str), where str is a string obect, and get sensible output in the Serial monitor.
That statement is nonsense. First, there is no such thing as a string object. There is a String class; there can be String objects. Second, it IS possible to print a String object.
http://snippets-r-us.com might be able to help you with your snippets.
Robin2
November 29, 2015, 10:55am
3
@boylesg , post your complete program - or (better still) a short complete program that illustrates your problem.
I have never had a problem with Serial.println("This is a test");
or Serial.println(receivedChars);
...R
Some ways to print a string
void setup() {
Serial.begin(115200);
String str = "A String";
Serial.println(str);
for(int i=0; i<str.length(); i++) {
Serial.print(str.charAt(i));
}
Serial.println();
Serial.println(str.c_str());
for(const char* p=str.c_str(); *p; ) {
Serial.print(*p++);
}
Serial.println();
}
void loop() {}
A String
A String
A String
A String
system
November 29, 2015, 12:35pm
5
Whandall:
Some ways to print a string String
void setup() {
Serial.begin(115200);
String str = "A String";
Serial.println(str);
for(int i=0; i<str.length(); i++) {
Serial.print(str.charAt(i));
}
Serial.println();
Serial.println(str.c_str());
for(const char* p=str.c_str(); *p; ) {
Serial.print(*p++);
}
Serial.println();
}
void loop() {}
A String
A String
A String
A String