Questions tagged [string]
A sequence of characters -- including letters, numbers and symbols -- often used for representing information in a human-readable format.
325 questions
71
votes
12
answers
458k
views
How do I split an incoming string?
I am sending a list of servo positions via the serial connection to the arduino in the following format
1:90&2:80&3:180
Which would be parsed as:
servoId : Position & servoId : Position &...
55
votes
12
answers
279k
views
How do I print multiple variables in a string?
Say I have some variables that I want to print out to the terminal, what's the easiest way to print them in a string?
Currently I do something like this:
Serial.print("Var 1:");Serial.println(var1);
...
17
votes
1
answer
160k
views
Convert int to char[]
I'm looking to convert an int value to a char array. currently I've found the following will return [number]
int num = [number]
str = String(num);
str.toCharArray(cstr,16);
Serial.println(cstr);
...
12
votes
6
answers
5k
views
Using String instead of C string, yet another attempt to touch a loaded issue
I've been reading a lot over the years why we should not use the notorious String class and how heap fragmentation is bad practice and not professional and we should never use it in our programs or we'...
10
votes
5
answers
69k
views
formatting strings in Arduino for output
I wander what is the best option for formatting strings in Arduino for output.
I mean what's a preferable way in the point of view of performance, memory usage – things like that.
I see, people ...
10
votes
1
answer
22k
views
Arduino Convert std:string to String
I'm working on BLE project with espressif library. And It returns me founded BLE device.
std::string getManufacturerData();
std::string getName();
int getRSSI();
BLEScan* getScan();
When ...
9
votes
3
answers
33k
views
Creating formatted String (including floats) in Arduino-compatible C++
I'm using a Mega2560 and a generic SSD1306 OLED display with the Adafruit_SSD1306 (and by extension, Adafruit_gfx) library.
I need to print a bunch of float values (ranging between 30.0 and 99.9) to ...
8
votes
3
answers
2k
views
Why is 'n' parameter of snprintf ignored?
I have found that the n parameter of snprintf() seems to be ignored in my code.
char asdf[10];
Serial1.println(snprintf(asdf, 2, "hello"));
This prints 5 when I would expect it to print 2. What is ...
8
votes
2
answers
2k
views
Convert a Bitstring into an integer value
I have got a String filled up with 0 and 1 and would like to get an Integer out of it:
String bitString = "";
int Number;
int tmp;
bitString = "";
for (i=1;i<=10;i++)
{
tmp= analogRead (...
8
votes
1
answer
7k
views
Is it better to use c_str or toCharArray?
When reading/trying a recent answer, I was surprised to see that Arduino's String class supports the c_str() method, just like the C++ std::string class. As expected, it appears to get a pointer to ...
7
votes
7
answers
11k
views
Understanding why should avoid “String” and alternative solutions
Why “Strings” are bad for Arduino?
Which is the most efficient and fastest solution to read and store the data from Accelerometer and GPS?
Stings are evil for Arduino
An Uno or other ATmega328-based ...
6
votes
3
answers
9k
views
Arduino String memory allocation
When a String variable is declared and modified inside a function, where does it go? To the heap(as string declaration is a part of dynamic memory allocation) or to the stack(as it is a part of ...
6
votes
3
answers
5k
views
How to multiply strings?
I want to have a line like this
Serial.println(count*"B");
So if count=6, it would print BBBBBB, etc.
Is there anything like this for arduino?
6
votes
1
answer
4k
views
Serial.write and Serial.println return different values? Cannot use correct ones
I have a text file on an SD card, and I am trying to print the lines to the serial monitor.
This Code Works:
#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(...
6
votes
1
answer
6k
views
Format Integer in Arduino
How to format an integer as 3 digit string? If I give 3 formated string should be 003
printf("%03d\n", 3); // output: 003
This doesn't work in Arduino.