ScrambleString(string[]).. Help please. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: ScrambleString(string[]).. Help please. (
/showthread.php?tid=330421)
ScrambleString(string[]).. Help please. -
introzen - 01.04.2012
So basically, I want a function which takes a string, mixes the letters up together and throws them around, making "doomsday" to "dodsaymo" or something.
Don't post the function. Just hints and tips on what functions I need to make this.
Re: ScrambleString(string[]).. Help please. -
steki. - 01.04.2012
Just a quick question: Are you applying for 3rd party dev on LS-RP?
Re: ScrambleString(string[]).. Help please. -
chrism11 - 01.04.2012
save it as 2 strings, use a loop and string1[i+1] = 'h'; // what ever letter you want, i guess that a hint
Re: ScrambleString(string[]).. Help please. -
introzen - 01.04.2012
How could you guess lol
Re: ScrambleString(string[]).. Help please. -
introzen - 01.04.2012
Quote:
Originally Posted by chrism11
save it as 2 strings, use a loop and string1[i+1] = 'h'; // what ever letter you want, i guess that a hint
|
Okey. That'd be enough. don't post anymore hints lol.
AW: ScrambleString(string[]).. Help please. -
Nero_3D - 01.04.2012
That would be my solution
- 1. Get the length of the string
- 2. Get an random index with the length, random(length)
- 3. Saving this char in a variable
- 4. Shifting the other character to the right to free the left most position and fill the position where we took our char from
- 5. Now we put the char in his new position, the left most
- 6. Repeating step 2 - 5 and decreasing the length by one and increasing the start position (where we put the char in)
- 7. Repeating step 2 - 6 till the length is lower than 2 (its nonsense to swap 1 char with itself)
If you use an second array you can skip step 3 - 5 and put the char directly in his new position in the second array
Re: ScrambleString(string[]).. Help please. -
Lidorrr - 01.05.2012
Quote:
Originally Posted by introzen
Okey. That'd be enough. don't post anymore hints lol.
|
Hey, can you publish the function here please?
Re: ScrambleString(string[]).. Help please. -
Hiddos - 01.05.2012
Well you could do something like this:
pawn Код:
new originalstring[size]; // originalstring contains the string to be scrambled
new scrambledstring[size]; // this will contain the scrambled string
new rand;
for(new i = 0, j = strlen(originalstring); i != j; i++)
{
do
{
rand = random(j);
}
while(scrambledstring[rand] != 0);
scrambledstring[rand] = originalstring[i];
}
Re: ScrambleString(string[]).. Help please. -
mamorunl - 01.05.2012
There are sorting algorithms, why not use one of those and take a weird sorting algorithm?