In a string, replace every occurrence of <0xYZ> with the character of hex value YZ. The < and > characters will be used only for that purpose, the string is guaranteed to be well formatted.
Example (‘0’ = 0x30): A<0x30>B => A0B
It’s an easy task, but there are many solutions and I was wondering about the best way to do it.
I think that a regular expression replace is the easiest way:
By matching an exact pattern it places less restrictions on the string, for example that the
<and>characters can still be used. Also, if a tag would happen to be malfomed, it will simply be left unchaged instead of causing an exception.This will replace tags like
<0X4A>and<0x4a>, but leave for example<0x04a>unchanged.