Jump to content

_ConvertLHWebColor()/_ConvertSHWebColor() - Convert web colours from shorthand to longhand and vice versa.


Recommended Posts

Posted (edited)

Convert a web colour from longhand to shorthand.

#include <MsgBoxConstants.au3>

MsgBox($MB_SYSTEMMODAL, '', '#FFFFFF: ' & _ConvertLHWebColor('#FFFFFF'))
MsgBox($MB_SYSTEMMODAL, '', '#EEFFCC: ' & _ConvertLHWebColor('#EEFFCC'))
MsgBox($MB_SYSTEMMODAL, '', '0B0033: ' & _ConvertLHWebColor('0B0033'))

Func _ConvertLHWebColor($sColor)
    Return StringRegExpReplace($sColor, '^(#|0[xX])?([[:xdigit:]])\2([[:xdigit:]])\3([[:xdigit:]])\4$', '\1\2\3\4')
EndFunc   ;==>_ConvertLHWebColor
Convert a web colour from shorthand to longhand.

#include <MsgBoxConstants.au3>

MsgBox($MB_SYSTEMMODAL, '', '#FFF: ' & _ConvertSHWebColor('#FFF'))
MsgBox($MB_SYSTEMMODAL, '', '#EFC: ' & _ConvertSHWebColor('#EFC'))
MsgBox($MB_SYSTEMMODAL, '', '0x003: ' & _ConvertSHWebColor('0x003'))

Func _ConvertSHWebColor($sColor)
    Return StringRegExpReplace($sColor, '^(#|0[xX])?([[:xdigit:]])([[:xdigit:]])([[:xdigit:]])$', '\1\2\2\3\3\4\4')
EndFunc   ;==>_ConvertSHWebColor
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Added support for colours with a prefix of 0x or 0X.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 1 month later...
Posted (edited)

Funnily enough I actually needed this the other day when I was optimising a CSS stylesheet.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 2 months later...
Posted

Updated the code to work with AutoIt v3.3.10.0+.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...