I want to convert a three-digit hex color which is coming from HTML CSS to a six-digit hex color for Flex. Can anyone give me code to convert 3-digit hex colors to their 6-d
Other answers provided the process but I will provide the code using regex and the java programming language
String value = "#FFF";
value = value.replaceAll("#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])", "#$1$1$2$2$3$3");
The three digit hex colors are expanded by doubling each digit (see w3 spec).
So #F3A
gets expanded to #FF33AA
.
Double every digit: for example #A21
is equal to #AA2211
.
However this question is a duplicate of: convert to 3-digit hex color code
Kotlin version of Ovokerie's answer:
shortHexString.replace(Regex("#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])"), "#$1$1$2$2$3$3")
If you came here and is using Python, here's how:
hex_code = '#FFF'
new_hex_code = '#{}'.format(''.join(2 * c for c in hex_code.lstrip('#')))