29.11.2016, 14:36
Hi,
How to calculate how much hex codes is in text?
How to calculate how much hex codes is in text?
ishex(c)
return (('0' <= c <= '9') || ('A' <= toupper(c) <= 'F'));
ColorsInText(const str[])
{
new num, colors;
for(new i = 0, c, d; (c = str[i]) != EOS; i++)
{
if(c == '{')
{
num = 0;
for(d = i + 1; d < i + 7; d++)
{
if(!str[d]) break;
if(!ishex(str[d])) break;
num++;
}
if(num == 6 && str[d] == '}') colors++;
}
}
return colors;
}
new str[] = "{ASA}Hello {AAAAAA}there {FFFFFF}wazzap {AA}";
printf("Hex codes in text: %d",ColorsInText(str));
Actually embedded colors do not support the alpha channel, means it's only 6 characters.
Based on a color in format: 0xRRGGBBAA You have to pick: {RRGGBB} Or you use a color picker like this one: http://www.colorpicker.com/ Simply pick the Code in the box and put it between braces. |
{0000FF}blue {FF0000}red blue red