ScrambleString(string[]).. Help please.
#6

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
Reply


Messages In This Thread
ScrambleString(string[]).. Help please. - by introzen - 01.04.2012, 12:54
Re: ScrambleString(string[]).. Help please. - by steki. - 01.04.2012, 12:58
Re: ScrambleString(string[]).. Help please. - by chrism11 - 01.04.2012, 12:59
Re: ScrambleString(string[]).. Help please. - by introzen - 01.04.2012, 12:59
Re: ScrambleString(string[]).. Help please. - by introzen - 01.04.2012, 13:01
AW: ScrambleString(string[]).. Help please. - by Nero_3D - 01.04.2012, 14:32
Re: ScrambleString(string[]).. Help please. - by Lidorrr - 01.05.2012, 19:42
Re: ScrambleString(string[]).. Help please. - by Hiddos - 01.05.2012, 19:51
Re: ScrambleString(string[]).. Help please. - by mamorunl - 01.05.2012, 20:03

Forum Jump:


Users browsing this thread: 2 Guest(s)