Convert an HEX string into a byte array

Hi all, i am trying to convert an hex string into a byte array since i need to send it trough a socket to a server. Actually i have a string like this:

String s ="0003040506"

I need an output like this:

byte a[]={0x00,0x03,0x04,0x05}

How can i do this?
Thanks a lot for your help

Consider getting rid of Strings altogether. On AVR-based Arduinos, they cause memory problems and program crashes.

Although it takes a bit of study to master, the C-string library <string.h> is FAR more powerful and efficient than manipulating String objects.

'Assuming' the numerals will always have a leading zero, starting at the second character subtract 48 (see an ASCII table for why) from every other character. Print to the serial monitor for proof.

dougp:
'Assuming' the numerals will always have a leading zero, starting at the second character subtract 48 (see an ASCII table for why) from every other character. Print to the serial monitor for proof.

...but don't forget to allow for a..f and A..F

What is the source of the Hex data ?
Does it have to be in that format or do you have control of how it is formatted ?

AWOL:
...but don't forget to allow for a..f and A..F

The OP is interested for numerical data which is obvious from this declaration: byte a={0x00,0x03,0x04,0x05}. Are a..f and A..F equivalent? If not, why are you insisting on taking care of a..f?

GolamMostafa:
The OP is interested for numerical data which is obvious from this declaration: byte a={0x00,0x03,0x04,0x05}.

Maybe. But, oftentimes once an answer has seemingly been provided the OP will add a post such as: "That's great! Now I need to add xxx to complete this level."

GolamMostafa:
Are a..f and A..F equivalent? If not, why are you insisting on taking care of a..f?

On the aforementioned ASCII table they're not. And, since a lot of data comes via ASCII...

It's just accommodating the sender using either upper or lower case.