user22842: I have a character array called storebuffer that contains data from a POST submission and its in the format ssid=abcdef&pswd=ghijk. I wanted to extract everything after ssid= into one array called acqSSID and the portion after &pswd= into another array called acqPaswd. I tried using this but it does not seem to be working. MAX_STORE_BUFFER_LEN is 255. Can anyone help?
int ctr = 0;
for (ctr = 5; ctr < MAX_STORE_BUFFER_LEN; ctr++)
{
  if ( (storebuffer[ctr] == '&') && (storebuffer[ctr+1] == 'p') && (storebuffer[ctr+2] == 's') && (storebuffer[ctr+3] == 'w') && (storebuffer[ctr+4] == 'd') && (storebuffer[ctr+5] == '=') )
  {
    break;
  }
  acqSSID[ctr] = storebuffer[ctr];
}

Serial.print("acqSSID: ");
Serial.println(acqSSID);
Serial.print("ctr: ");
Serial.println(ctr);


user4143: You can simply chop it up in place without requiring more than a few extra bytes of RAM using strtok():
char storebuffer[] = "ssid=abcdef&pswd=ghijk";

// Slice it into two parts around the &:
char *lefthalf = strtok(storebuffer, "&");
if (lefthalf != NULL) { // We found a & and split the string OK
    char *righthalf = strtok(NULL, "&");

    // Now you can slice each half around the =
    char *ssidtag = strtok(lefthalf, "=");
    char *ssid = strtok(NULL, "=");
    char *pswdtag = strtok(righthalf, "=");
    char *pswdtag = strtok(NULL, "=");

    Serial.print("SSID: ");
    Serial.println(ssid);
    Serial.print("Password: ");
    Serial.println(pswd);
}

The existing string gets chopped up and the pointers point to different places:
ssid\0abcdef\0pswd\0ghijk
^     ^       ^     ^
1     2       3     4

1: ssidtag
2: ssid
3: pswdtag
4: pswd


22842: <p>I have a character array called <code>storebuffer</code> that contains data from a POST submission and its in the format <code>ssid=abcdef&amp;pswd=ghijk</code>. I wanted to extract everything after <code>ssid=</code> into one array called <code>acqSSID</code> and the portion after <code>&amp;pswd=</code> into another array called <code>acqPaswd</code>. I tried using this but it does not seem to be working. MAX_STORE_BUFFER_LEN is 255. Can anyone help?</p>

<pre><code>int ctr = 0;
for (ctr = 5; ctr &lt; MAX_STORE_BUFFER_LEN; ctr++)
{
  if ( (storebuffer[ctr] == '&amp;') &amp;&amp; (storebuffer[ctr+1] == 'p') &amp;&amp; (storebuffer[ctr+2] == 's') &amp;&amp; (storebuffer[ctr+3] == 'w') &amp;&amp; (storebuffer[ctr+4] == 'd') &amp;&amp; (storebuffer[ctr+5] == '=') )
  {
    break;
  }
  acqSSID[ctr] = storebuffer[ctr];
}

Serial.print("acqSSID: ");
Serial.println(acqSSID);
Serial.print("ctr: ");
Serial.println(ctr);
</code></pre>
 4143: <p>You can simply chop it up in place without requiring more than a few extra bytes of RAM using <code>strtok()</code>:</p>

<pre><code>char storebuffer[] = "ssid=abcdef&amp;pswd=ghijk";

// Slice it into two parts around the &amp;:
char *lefthalf = strtok(storebuffer, "&amp;");
if (lefthalf != NULL) { // We found a &amp; and split the string OK
    char *righthalf = strtok(NULL, "&amp;");

    // Now you can slice each half around the =
    char *ssidtag = strtok(lefthalf, "=");
    char *ssid = strtok(NULL, "=");
    char *pswdtag = strtok(righthalf, "=");
    char *pswdtag = strtok(NULL, "=");

    Serial.print("SSID: ");
    Serial.println(ssid);
    Serial.print("Password: ");
    Serial.println(pswd);
}
</code></pre>

<p>The existing string gets chopped up and the pointers point to different places:</p>

<pre><code>ssid\0abcdef\0pswd\0ghijk
^     ^       ^     ^
1     2       3     4

1: ssidtag
2: ssid
3: pswdtag
4: pswd
</code></pre>
