I need to display a QR code from an API on an OLED screen. My webhook returns a few strings, but one of them looks like the following:
<qrcode>0B01100110,0B10100101..</qrcode>
I can get the contents of the qrcode with a simple substring, however I’m not sure the best way to parse my comma delimited string into an array so the result is something like:
unsigned char* image[] = [ 0B01100110,0B10100101.. ]
After looking online for a while, I was suggested a vector and stringstream.
String id = tryExtractString(parsed, "<id>", "</id>");
String qrcode = tryExtractString(parsed, "<qrcode>", "</qrcode>");
String value = tryExtractString(parsed, "<value>", "</value>");
String units = tryExtractString(parsed, "<units>", "</units>");
if (id == NULL || qrcode == NULL || value == NULL || units == NULL) {
viewState = -1;
txInProgress = false;
return;
}
std::string _qrcode (qrcode);
std::stringstream ss(_qrcode);
std::vector<int> image;
std::string token;
while(std::getline(ss, token, ',')) {
image.push_back(token);
}
However, std::string token
cannot be pushed to vector<int> image
for obvious reasons, and stoi
is unavailable.
What would be the easiest way to do it?