AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Remove colors from a color formatted string. (https://forums.alliedmods.net/showthread.php?t=303698)

Chdata 12-17-2017 20:17

Remove colors from a color formatted string.
 
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)
                
}
            }
        }
    }




All times are GMT -4. The time now is 23:48.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.