GSC Illegally useful string conversations :D

Xeirh

Veteran
Messages
16
Reaction score
2
Points
793
works pretty simple:
* action: iprintln( capitalize_string( "capitalize me please" ) );
* return: Capitalize Me Please

Now the cool stuff!

item, let's say a level._effect: "grenade_samantha_steal"
* action: iprintln( capitalize_string( string_convert( "grenade_samantha_steal", "_", " " ) ) );
* return: Grenade Samantha Steal

string_convert can remove underscores and replace with space and vice versa or any target character.

Code:
capitalize_string( string ) {
    string = strtok( string, " " );
    for( a = 0; a < string.size; a++ )
        string[ a ] = capitalize_first_letter( string[ a ] );
    capitalize_string = "";
    for( a = 0; a < string.size; a++ )
        if( a < string.size - 1 )
            capitalize_string += string[ a ] + " ";
    capitalize_string += string[ string.size - 1 ];
    return capitalize_string;
}
capitalize_first_letter( string ) {
    capitalize_letter = "";
    capitalize_letter += toupper( string[ 0 ] );
    if( string.size <= 1 )
        return capitalize_letter;
    for( a = 1; a < string.size; a++ )
        capitalize_letter += string[ a ];
    return capitalize_letter;
}
Code:
string_convert( string, target, replace ) {
    convert = "";
    for( a = 0; a < string.size; a++ ) {
        if( string[ a ] == target )
            convert += replace;
        else
            convert += string[ a ];
        return convert;
     }
 }
Code:
toupper( string ) {
    lower = "abcdefghijklmnopqrstuvwxyz";
    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for( a = 0; a < lower.size; a++ ) {
        if( illegal_character( string ) )
            return string;
        if( string == lower[ a ] )
            return upper[ a ];
    }
    return string;
}
illegal_character( string ) {
    illegal = "*{}!^/-_$&@#()";
    for( a = 0; a < illegal.size; a++ )
        if( string == illegal[ a ] )
            return true;
    return false;
}
Capture_1.PNG

Capture.png


*Converters Created By Boy7* <- the warrior
 

Attachments

  • Capture_1.PNG
    Capture_1.PNG
    3.8 KB · Views: 71
  • Capture.png
    Capture.png
    94.5 KB · Views: 74
Last edited:

CF4_99

Veteran
Messages
145
Reaction score
56
Points
888
That method was actually created by extinct a long time ago. Only difference is the unnecessary utility functions that were added.

Here is my method of doing it. Which I personally find to be a lot better.


It does everything Extinct's method does, but it automatically replaces '_' with spaces. Along with a custom list of strings that will be removed from the final string output. It also capitalizes the first letter of the strings.

Just needs to be called like this: CleanString(<string>)
If the string contains spaces, and doesn't contain any underscores, it will just return the original string.

C++:
CleanString(string)
{
    if(string[0] == ToUpper(string[0]))
        if(IsSubStr(string, " ") && !IsSubStr(string, "_"))
            return string;
   
    string = StrTok(ToLower(string), "_");
    str = "";
   
    for(a = 0; a < string.size; a++)
    {
        //List of strings/chars what will be removed from the final string output
        strings = ["specialty", "zombie", "zm", "t7", "t6", "p7", "zmb", "zod", "ai", "g", "bg", "perk", "player", "weapon", "wpn", "aat", "bgb", "visionset", "equip", "craft", "der", "viewmodel", "mod", "fxanim", "moo", "moon", "zmhd", "fb", "bc", "asc", "vending"];
       
        //This will replace any '_' found in the string
        replacement = " ";

        if(!isInArray(strings, string[a]))
        {
            for(b = 0; b < string[a].size; b++)
                if(b != 0)
                    str += string[a][b];
                else
                    str += ToUpper(string[a][b]);
           
            if(a != (string.size - 1))
                str += replacement;
        }
    }
   
    return str;
}
 

Xeirh

Veteran
Messages
16
Reaction score
2
Points
793
That method was actually created by extinct a long time ago. Only difference is the unnecessary utility functions that were added.

Here is my method of doing it. Which I personally find to be a lot better.


It does everything Extinct's method does, but it automatically replaces '_' with spaces. Along with a custom list of strings that will be removed from the final string output. It also capitalizes the first letter of the strings.

Just needs to be called like this: CleanString(<string>)
If the string contains spaces, and doesn't contain any underscores, it will just return the original string.

C++:
CleanString(string)
{
    if(string[0] == ToUpper(string[0]))
        if(IsSubStr(string, " ") && !IsSubStr(string, "_"))
            return string;
  
    string = StrTok(ToLower(string), "_");
    str = "";
  
    for(a = 0; a < string.size; a++)
    {
        //List of strings/chars what will be removed from the final string output
        strings = ["specialty", "zombie", "zm", "t7", "t6", "p7", "zmb", "zod", "ai", "g", "bg", "perk", "player", "weapon", "wpn", "aat", "bgb", "visionset", "equip", "craft", "der", "viewmodel", "mod", "fxanim", "moo", "moon", "zmhd", "fb", "bc", "asc", "vending"];
      
        //This will replace any '_' found in the string
        replacement = " ";

        if(!isInArray(strings, string[a]))
        {
            for(b = 0; b < string[a].size; b++)
                if(b != 0)
                    str += string[a][b];
                else
                    str += ToUpper(string[a][b]);
          
            if(a != (string.size - 1))
                str += replacement;
        }
    }
  
    return str;
}
yeah that is alot better made another one that removes zm, t6 and other stuff. thanks for this tho
 
Top