CFLib.org – Common Function Library Project

HexToRGB(hexColor)

Last updated November 06, 2001

author

Eric Carlisle

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
HexToRGB is the opposite of RGBtoHex. HexToRGB converts a 6 character hexadecimal color value into an RGB list (rr,gg,bb).

Return Values:
Returns a string.

Example:

<CFSET Color="33ccff">
<cfoutput>
The RGB values for #Color# are: #HextoRGB(Color)#
</cfoutput>

Parameters:

Name Description Required
hexColor 6 character hexadecimal color value. Yes

Full UDF Source:

/**
 * Convert a hexadecimal color into a RGB color value.
 * 
 * @param hexColor      6 character hexadecimal color value. 
 * @return Returns a string. 
 * @author Eric Carlisle (ericc@nc.rr.com) 
 * @version 1.0, November 6, 2001 
 */
function HexToRGB(hexColor){
  /* Strip out poundsigns. */
  Var tHexColor = replace(hexColor,'##','','ALL');
    
  /* Establish vairable for RGB color. */
  Var RGBlist='';
  Var RGPpart='';    

  /* Initialize i */
  Var i=0;

  /* Loop through each hex triplet */
  for (i=1; i lte 5; i=i+2){
    RGBpart = InputBaseN(mid(tHexColor,i,2),16);
    RGBlist = listAppend(RGBlist,RGBpart);
  }
  return RGBlist;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson