SA-MP Forums Archive
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 solutionIf 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?