Does the version of C++ that comes with Arduino have a StringBuilder class ?
I know several other languages have a command that will make it easy build long strings.
Thanks
Does the version of C++ that comes with Arduino have a StringBuilder class ?
I know several other languages have a command that will make it easy build long strings.
Thanks
Why do you need to build long strings?
You can look at cStrings and associated functions, the String class and associated methods or the standard c++ string class
strcat()
Thank you for that. Other languages offer a StringBuilder Class allows you to build long strings.
ex: myLongString = StringBuilder("x", 80) ' Returns a string of 'x's 80 chrs long w/o repeatedly appending characters in memory.
Any idea how to do that on the Arduino ?
char str[80];
memset(str, 'x', 80);
@cedarlakeinstruments
That’s a memory buffer full of x but missing the trailing null char to make it a cString
@sid3 again what’s the use case? You might be better off to put the string in flash memory for example if it’s read only like printing a long line of ———————-
to separate things on the Serial monitor
Should be 81 chars buffer to hold the terminating zero.
The "standard" Arduino is the Uno with 2048 bytes of RAM and 32KB flash for program and constant data.
The Arduino Serial output buffer is 64 chars long. You can fill it by printing to it. But one thing, it works better at high baud rate... Serial begin at 115200 or more if possible just to clear the send buffer quicker to avoid overload and delay.
Would take less memory to have a for loop print a single hyphen 80 times.
I would not recommend it, but the OP could define a function that literally adds a character to a String or c-string the specified number of times.
yes fair point and very likely true.
Let's see in practice:
inline void printSeparator() {
static const char separator[] PROGMEM = "--------------------------------------------------------------------------------";
Serial.print((__FlashStringHelper *)separator);
}
void setup() {
Serial.begin(115200); Serial.println();
printSeparator();
}
void loop() {}
this is using 1568 bytes of flash on a UNO and 188 bytes of SRAM
Now with the for loop:
inline void printSeparator() {
for (byte i = 0; i < 80; i++) Serial.write('-');
}
void setup() {
Serial.begin(115200); Serial.println();
printSeparator();
}
void loop() {}
this is using 1474 bytes of flash on a UNO and 188 bytes of SRAM
so we save 1568 - 1474 = 94 bytes !
So, I'm going to weasel out of that by saying String implementations in languages other than C typically use a length property instead of a null terminator
but probably would not be happy for you to mess around with the underlying buffer using memset() then
touche'!
(why can't I get accents to display?)
Touché accents do work !
(Easier with a French keyboard)
Or Alt Codes
é
I tried using keyboard alt codes, but didn't work. Now that I think of it, on this PC I have one of the "I can kill you with this keyboard" IBM Model M's. Maybe it simply doesn't send some key combinations? That seems unlikely, but I can't get it to work.
However, from alt-codes.net I can copy & paste, so thanks.
I think it only works with NumLock.
é
Yes!!! I can't believe I had forgotten that. Thank you.
It's "Option-e" for the accent followed by 'e' (the letter under the accent) on the Mac keyboard.
On an iPhone/iPad, hold down the 'e' button and select the accented version you want from the menu that pops up.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.