user66000: My apologies if this is a naive question. How do I convert a String which has hex values to a byte array that has those hex values?
This:
String s = "0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff";

Needs to be converted to this:
char test[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

I used the following procedure. It does convert it, however, each character is saved as a character as opposed to hex value:
unsigned int str_len = s.length() + 1;
char charArray[str_len];
s.toCharArray(charArray, str_len);

Any help will be appreciated. Thank you!

user58246: There are C functions that can convert text to number. For example, strtol() or atoi(). Here is a little snippet to get you started:
char *str = "FF";
char *ptr;
int result = strtol(str, &ptr, 16); //the 16 is the base the string is in (HEX -> base 16)


result will have 0xFF or 255 by the end. You can use this to achieve what you are trying to do. Take a look at this for functions you can use to manage your String.

user40646: You only convert the String object to a char array. It need to further split the char array into substring, and then convert it to number.
To split the char array, you can use strtok() function in c++ to do the job.
There is no str conversion function that can convert "0xff" into uint8_t directly. However, as @rubemnobre mentioned strtol() can be used to convert a c string to a long (in Arduino, it is 4-byte number) and further cast into a uint8_t and store in a byte array.
String s = "0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff";

// Convert String object to char array
unsigned int str_len = s.length()+1;
char charArray[str_len];
s.toCharArray(charArray, str_len);

uint8_t byteArray[7];
int i=0;

// split charArray at each ',' and convert to uint8_t
char *p = strtok(charArray, ",");
while(p != NULL) {
  byteArray[i++] = strtoul(p, NULL, 16);
  p = strtok(NULL, ",");
}

// Print the byteArray
for (i=0; i<sizeof(byteArray)/sizeof(char); i++) {
  Serial.print(byteArray[i]);
  Serial.println(", ");
}
Serial.println();


66000: 
<p>My apologies if this is a naive question. How do I convert a <code>String</code> which has hex values to a byte array that has those hex values?</p>
<p>This:</p>
<pre class="lang-arduino prettyprint-override"><code>String s = &quot;0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff&quot;;
</code></pre>
<p>Needs to be converted to this:</p>
<pre class="lang-arduino prettyprint-override"><code>char test[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
</code></pre>
<p>I used the following procedure. It does convert it, however, each character is saved as a character as opposed to hex value:</p>
<pre class="lang-arduino prettyprint-override"><code>unsigned int str_len = s.length() + 1;
char charArray[str_len];
s.toCharArray(charArray, str_len);
</code></pre>
<p>Any help will be appreciated. Thank you!</p>
 58246: 
<p>There are C functions that can convert text to number. For example, <a href="https://www.tutorialspoint.com/c_standard_library/c_function_strtol.htm" rel="nofollow noreferrer"><code>strtol()</code></a> or <code>atoi()</code>. Here is a little snippet to get you started:</p>
<pre class="lang-arduino prettyprint-override"><code>char *str = &quot;FF&quot;;
char *ptr;
int result = strtol(str, &amp;ptr, 16); //the 16 is the base the string is in (HEX -&gt; base 16)

</code></pre>
<p><code>result</code> will have <code>0xFF</code> or <code>255</code> by the end. You can use this to achieve what you are trying to do. Take a look at <a href="https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/" rel="nofollow noreferrer">this</a> for functions you can use to manage your <code>String</code>.</p>
 40646: 
<p>You only convert the String object to a char array. It need to further split the char array into substring, and then convert it to number.</p>
<p>To split the char array, you can use <a href="https://www.cplusplus.com/reference/cstring/strtok/" rel="nofollow noreferrer">strtok()</a> function in c++ to do the job.</p>
<p>There is no str conversion function that can convert <code>&quot;0xff&quot;</code> into <code>uint8_t</code> directly. However, as @rubemnobre mentioned <a href="https://www.cplusplus.com/reference/cstdlib/strtol/" rel="nofollow noreferrer">strtol()</a> can be used to convert a c string to a <code>long</code> (in Arduino, it is 4-byte number) and further cast into a <code>uint8_t</code> and store in a byte array.</p>
<pre class="lang-arduino prettyprint-override"><code>String s = &quot;0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff&quot;;

// Convert String object to char array
unsigned int str_len = s.length()+1;
char charArray[str_len];
s.toCharArray(charArray, str_len);

uint8_t byteArray[7];
int i=0;

// split charArray at each ',' and convert to uint8_t
char *p = strtok(charArray, &quot;,&quot;);
while(p != NULL) {
  byteArray[i++] = strtoul(p, NULL, 16);
  p = strtok(NULL, &quot;,&quot;);
}

// Print the byteArray
for (i=0; i&lt;sizeof(byteArray)/sizeof(char); i++) {
  Serial.print(byteArray[i]);
  Serial.println(&quot;, &quot;);
}
Serial.println();
</code></pre>
