StrToHacker - Converts a string into Hacker Talk

StrToHacker was originally created for SA-MP, to enable it's scripters to convert their speech to look like hackers ingame. Now I have created it to suit multiple languages.

[C#]

///<summary>
///converts a string to leet-speak/hacker talk.
///</summary>
///<param name="str">string to convert to leet-speak/hacker talk</param>
///<returns>the converted string</returns>

    public string StrToHacker(string str)
    {
        // Declare the string we will use to create the return.
        string result = "";

        // Loop through the string's char's.
        for (int i = 0; i < str.Length; i++)
        {
            /* Replace char with those defined in this list. Note '\\' are regular
             * '\', remember you must use escape codes when doing this.
             */ 
            switch (str[i])
            {
                case 'a': result += "4"; break;
                case 'b': result += "13"; break;
                case 'c': result += "("; break;
                case 'd': result += "|)"; break;
                case 'e': result += "3"; break;
                case 'f': result += "1="; break;
                case 'g': result += "6"; break;
                case 'h': result += "#"; break;
                case 'i': result += "|"; break;
                case 'j': result += "_l"; break;
                case 'k': result += "|<"; break;
                case 'l': result += "l_"; break;
                case 'm': result += "l\\/l"; break;
                case 'n': result += "l/l"; break;
                case 'o': result += "0"; break;
                case 'p': result += "l*"; break;
                case 'q': result += "&"; break;
                case 'r': result += "l2"; break;
                case 's': result += "5"; break;
                case 't': result += "7"; break;
                case 'u': result += "l_l"; break;
                case 'v': result += "\\/"; break;
                case 'w': result += "\\/\\/"; break;
                case 'x': result += "><"; break;
                case 'y': result += "¥"; break;
                case 'z': result += "2"; break;
                default: result += str[i]; break; // We didn't find something to convert, so just ignore it.
            }
        }
        // Return the haxified string into a variable.
        return result;
}

[PAWN]

stock StrToHacker(string[])
{
    new len = strlen(string);
    new result[256];
    for(new i; i < len; i++)
    {
        switch(string[i])
        {
             case 'a': format(result, sizeof(result), "%s4", result);
             case 'b': format(result, sizeof(result), "%sl3", result);
             case 'c': format(result, sizeof(result), "%s(", result);
             case 'd': format(result, sizeof(result), "%s|)", result);
             case 'e': format(result, sizeof(result), "%s3", result);
             case 'f': format(result, sizeof(result), "%sl=", result);
             case 'g': format(result, sizeof(result), "%s6", result);
             case 'h': format(result, sizeof(result), "%s#", result);
             case 'i': format(result, sizeof(result), "%s|", result);
             case 'j': format(result, sizeof(result), "%s_l", result);
             case 'k': format(result, sizeof(result), "%s|<", result);
             case 'l': format(result, sizeof(result), "%sl_", result);
             case 'm': format(result, sizeof(result), "%sl\\/l", result);
             case 'n': format(result, sizeof(result), "%sl/l", result);
             case 'o': format(result, sizeof(result), "%s0", result);
             case 'p': format(result, sizeof(result), "%sl*", result);
             case 'q': format(result, sizeof(result), "%s&", result);
             case 'r': format(result, sizeof(result), "%sl2", result);
             case 's': format(result, sizeof(result), "%s5", result);
             case 't': format(result, sizeof(result), "%s7", result);
             case 'u': format(result, sizeof(result), "%sl_l", result);
             case 'v': format(result, sizeof(result), "%s\\/", result);
             case 'w': format(result, sizeof(result), "%s\\/\\/", result);
             case 'x': format(result, sizeof(result), "%s><", result);
             case 'y': format(result, sizeof(result), "%s¥", result);
             case 'z': format(result, sizeof(result), "%s2", result);
             default: format(result, sizeof(result), "%s%c", result, string[i]); // Unrecognised Symbol
         }
    }
    return result;
}

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License