How to convert 3-digit HTML hex colors to 6-digit flex hex colors

前端 未结 5 368
無奈伤痛
無奈伤痛 2020-12-31 00:43

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

相关标签:
5条回答
  • 2020-12-31 00:52

    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");
    
    0 讨论(0)
  • 2020-12-31 01:04

    The three digit hex colors are expanded by doubling each digit (see w3 spec). So #F3A gets expanded to #FF33AA.

    0 讨论(0)
  • 2020-12-31 01:05

    Double every digit: for example #A21 is equal to #AA2211.

    However this question is a duplicate of: convert to 3-digit hex color code

    0 讨论(0)
  • 2020-12-31 01:07

    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")
    
    0 讨论(0)
  • 2020-12-31 01:10

    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('#')))
    
    0 讨论(0)
提交回复
热议问题