View Single Post
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-17-2017 , 20:17   Remove colors from a color formatted string.
Reply With Quote #1

This is something I ended up needing for a plugin that sends command results through a socket to a bot, to get rid of color codes from chat messages formatted by morecolors or similar.

Not the most efficient but it works.

PHP Code:
stock void RemoveColorCodes(char[] szTextint iSize)
{
    for (
int i 0iSize && szText[i] != '\0'i++)
    {
        if (
szText[i] >= '\1' && szText[i] <= '\6')
        {
            
strcopy(szText[i], iSize-iszText[i+1]);
        }
        else
        {
            switch (
szText[i])
            {
                case 
'\7':
                {
                    
strcopy(szText[i], iSize-iszText[i+4]); // \x07%06X \x07 0x3E FF 3E (4 bytes)
                
}
                case 
'\8':
                {
                    
strcopy(szText[i], iSize-iszText[i+5]); // \x08 00 00 00 32 (5 bytes)
                
}
            }
        }
    }

__________________

Last edited by Chdata; 12-17-2017 at 20:18.
Chdata is offline