cookiemonster Posted June 30, 2016 Posted June 30, 2016 Hoping for some guidance, I have a string like: $string='vXx2586578£&' How can I go abouts shuffling the contents of the string?
argumentum Posted June 30, 2016 Posted June 30, 2016 make an array and do the shuffling, then reconstruct the string Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
czardas Posted June 30, 2016 Posted June 30, 2016 #include <Array.au3> Local $string = 'vXx2586578£&' Local $aChars = StringSplit($string, "", 2) _ArrayShuffle($aChars) Local $sNewString For $i = 0 To UBound($aChars) - 1 $sNewString &= $aChars[$i] Next MsgBox(0, "New String", $sNewString) cookiemonster 1 operator64 ArrayWorkshop
jguinch Posted July 1, 2016 Posted July 1, 2016 Also this one : Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
cookiemonster Posted July 1, 2016 Author Posted July 1, 2016 8 hours ago, czardas said: #include <Array.au3> Local $string = 'vXx2586578£&' Local $aChars = StringSplit($string, "", 2) _ArrayShuffle($aChars) Local $sNewString For $i = 0 To UBound($aChars) - 1 $sNewString &= $aChars[$i] Next MsgBox(0, "New String", $sNewString) Works perfectly, I had tried doing it this way but messed part of it up, thanks for clarification. czardas 1
Moderators JLogan3o13 Posted July 1, 2016 Moderators Posted July 1, 2016 A few less lines: #include <Array.au3> Local $string = 'vXx2586578£&' Local $aChars = StringSplit($string, "", 2) _ArrayShuffle($aChars) MsgBox(0, "New String", StringReplace(_ArrayToString($aChars), "|", "")) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
UEZ Posted July 1, 2016 Posted July 1, 2016 Here the non array version: Global $string='1234567890' ConsoleWrite(ShuffleChars($string) & @CRLF) Func ShuffleChars($sString, $iRounds = 1) Local $sTemp1, $sTemp2, $i, $j, $r, $t, $iLen, $rnd, $sLeft, $sMid, $sRight $iLen = StringLen($sString) For $r = 1 To $iRounds For $i = 1 To $iLen $j = $i $rnd = Random(1, $iLen, 1) If $rnd = $i Then ContinueLoop If $j < $rnd Then $t = $j $j = $rnd $rnd = $t EndIf $sTemp1 = StringMid($sString, $rnd, 1) $sTemp2 = StringMid($sString, $j, 1) $sLeft = StringMid($sString, 1, $rnd - 1) $sMid = StringMid($sString, $rnd + 1, $j - $rnd - 1) $sRight = StringMid($sString, $j + 1) $sString = $sLeft & $sTemp2 & $sMid & $sTemp1 & $sRight Next Next Return $sString EndFunc Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
iamtheky Posted July 1, 2016 Posted July 1, 2016 meant to post this here not in JG's example -with powershell #include<AutoItConstants.au3> #include <Array.au3> $Str = "shuffling" $iPID = run("powershell -join ('" & _ArrayToString(stringsplit($Str , "" , 2) , "','") & "' | Get-Random -Count " & StringLen($Str) & ")" , "" , @SW_HIDE , $stdout_child) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop WEnd msgbox(0, '' , $sOutput) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Moderators JLogan3o13 Posted July 1, 2016 Moderators Posted July 1, 2016 AutoIt is like Burger King, you get so many great ways of doing things, you can have it your way argumentum 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
UEZ Posted July 1, 2016 Posted July 1, 2016 12 minutes ago, JLogan3o13 said: AutoIt is like Burger King Bad taste Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
jguinch Posted July 1, 2016 Posted July 1, 2016 @iamtheky : ah OK, I didn't really understand why you posted in the Example post (it already happened to me) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
iamtheky Posted July 1, 2016 Posted July 1, 2016 The one time i would have used the delete button properly... ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Danyfirex Posted July 1, 2016 Posted July 1, 2016 Hello I did this just for fun. it's based on swapping. Local $string = 'vXx2586578£&' ConsoleWrite(_StringShuffle($string) & @CRLF) ConsoleWrite(_StringShuffle($string) & @CRLF) Func _StringShuffle($sString) Local $iRnd1 = 0 Local $iRnd2 = 0 Local $sChar1 = "" Local $sChar2 = "" Local $iMax = StringLen($sString) For $i = 1 To $iMax $iRnd1 = Random(1, $iMax, 1) $iRnd2 = Random(1, $iMax, 1) $sChar1 = StringMid($sString, $iRnd1, 1) $sChar2 = StringMid($sString, $iRnd2, 1) $sString = StringReplace($sString, $iRnd1, $sChar2) $sString = StringReplace($sString, $iRnd2, $sChar1) Next Return $sString EndFunc Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now