// Function to convert hex string with "0x" prefix into 6-digit color code format // (called from setColorByRgb) string formatColorCode(string code){ // Get original string length int length = countText(code); // Remove the "0x" prefix code = cropText(code, 2, length); length -= 2; // Calculate how many leading zeros are needed int zeros = 6 - length; // Pad the beginning with zeros to make it 6 digits for(int i=0; i<zeros; i++){ code = "0" + code; } return code; }