Creating string on the core

Is there a different syntax to use to make strings on the core? I’m trying to create a giant string of times and parse it later, but none of these are compiling for me (ignore the comment outs):

> //std::basic_string<char>* stringTime[10];
> //const string stringTime[];
> //std::string stringTime[];
> //string stringTime[];
> //char * stringTime[];
> //typedef vector<string> stringTime;

also using these:

> #include <iostream>
> #include <string>
> #include <vector>
> using namespace std;

This is what I’m essentially trying to read out…

stringTime = stringTime + strokeCount + pressTime;
            sprintf(publishTime, "%e", stringTime);
            Spark.publish("getTime", publishTime);

^not sure if %e or %u or %f or what’s appropriate there either…

any help would be awesome!!!

@bko, I did read your string class tutorial, so wondering if you could provide any feedback on this problem as well.

Any suggestions would be greatly appreciated!!!

Hi @jkkim93

There are two basic kinds of strings on Arduino and Spark, the char array string and the Arduino String object. You seem to looking for the C++ stardard library strings which would take up too many resources on a small micro-controller.

You would probably be happy with Arduino String objects based on your example. They can have memory usage issues, but you should be OK. There is a way to convert an Arduino String object to a C char array too.

String stringTime;
stringTime += strokeCount;
stringTime += pressTime;
char publishTime[64];
stringTime.toCharArray(publishTime,64);
Spark.publish("getTime",publishTime);
1 Like

@bko, if I pass the charArray into the getTime fn and try to read it by parsing the JSON, would it not read by doing JSON.data? I’m wondering if because it’s a string not an int or long, if its parsed state is not retrievable through ".dara"
thanks for all your help!