Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. // Aufrufen
  2. String GetVar = getStringPartByNr(packetBuffer, ',', 1);
  3.  
  4. // Funktion
  5. String getStringPartByNr(const String &data, char separator, int index)
  6. {
  7. // -----------------------------------------
  8. // --Split String mit Seperator und index---
  9. // -----------------------------------------
  10.  
  11. int found = 0;
  12. int strIndex[] = {0, -1};
  13. int maxIndex = data.length() - 1;
  14.  
  15. for (int i = 0; i <= maxIndex && found <= index; i++)
  16. {
  17. if (data.charAt(i) == separator || i == maxIndex)
  18. {
  19. found++;
  20. strIndex[0] = strIndex[1] + 1;
  21. strIndex[1] = (i == maxIndex) ? i + 1 : i;
  22. }
  23. }
  24. return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement