Skip to content

Instantly share code, notes, and snippets.

@unlocomqx
Created August 20, 2018 18:43
Show Gist options
  • Save unlocomqx/e77e249666dc8cb05207f5c56d6b9892 to your computer and use it in GitHub Desktop.
Save unlocomqx/e77e249666dc8cb05207f5c56d6b9892 to your computer and use it in GitHub Desktop.
A simple function to take a string chunk in arduino
String getChunk(String str, String delimiter, int index) {
int prev_idx = 0;
int idx = 0;
String temp = str;
String chunk;
int i = 0;
do {
idx = temp.indexOf(delimiter);
debug("idx =", String(idx));
chunk = temp.substring(prev_idx, idx);
debug("temp =", temp);
debug("chunk =", chunk);
temp = temp.substring(idx + 1);
i++;
} while(idx != -1 && i < index);
return chunk;
}
// +CMGR: “REC READ”,”+21654130026”,,”04/08/28,22:26:29+40″
// String number = getChunk(str, ",", 2);
// => number = ”+21654130026”
// this would need some imporvements though (use pointer instead of strings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment