View Single Post
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 05-17-2018 , 13:52   Re: Place a char before every char
Reply With Quote #2

I'm sure there's better ways than the following but with understanding the basic functions and logic you can become creative with many ways to a solution.

PHP Code:
stock PlaceCharInfrontOfAllCharsInString(String:input[512], char thechar)
{
    new 
maxlen = (strlen(input) * 2) + 1;
    if(
maxlen 512)
        return;
        
    
decl String:temp[512];
    
    for(
int i 0;i<strlen(input);i++)
        
Format(tempsizeof(temp), "%s%c%c"tempthecharinput[i]);
        
    
Format(input512"%s"temp);

PHP Code:
decl String:test[512] = "abcde fgh";
PlaceCharInfrontOfAllCharsInString(test'1');
PrintToServer(test); 
Note: I'm sure Format isn't meant to use a function argument variable to write to its own buffer variable and has undefined behavior and may be exploitable or cause memory corruption within the destination string.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline