Replacing characters inside a string
#1

Alright so I've stumbled upon a problem while creating this, I am simply trying to make something that will replace certain parts (random parts) of a string.

Example

Normal String:
Quote:

Hello World

Output should have 10 random characters:
Quote:

Aqer Zxcas

Now currently my system is kinda glitchy.
1. It will replace few characters with exactly the same letter. For example it will replace 5 characters with a character S
2. Sometimes it will cut down the string. So for example you write "Hello world" and you will get the output "P"

pawn Код:
new LetterList[26][] =
{
    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
};
stock strReplaceChar(string[128]) {
    new text_lenght = strlen(string),
        rr = random(text_lenght);

    for(new i=0; i < text_lenght; i++) {
        if(!strcmp(string, " ")) continue; //just to avoid cutting down the spaces
        strreplace(string, string[rr], LetterList[random(sizeof(LetterList))], true, .maxlength = 128);
    }
    return string;
}
Reply


Messages In This Thread
Replacing characters inside a string - by TwinkiDaBoss - 16.11.2016, 00:08
Re: Replacing characters inside a string - by SickAttack - 16.11.2016, 00:20
Re: Replacing characters inside a string - by TwinkiDaBoss - 16.11.2016, 00:32
Re: Replacing characters inside a string - by SickAttack - 16.11.2016, 00:43
Re: Replacing characters inside a string - by TwinkiDaBoss - 16.11.2016, 00:55
Re: Replacing characters inside a string - by SickAttack - 16.11.2016, 00:59
Re: Replacing characters inside a string - by TwinkiDaBoss - 16.11.2016, 01:03
Re: Replacing characters inside a string - by Vince - 16.11.2016, 05:24

Forum Jump:


Users browsing this thread: 2 Guest(s)