FrankwazHere Posted September 5, 2009 Share Posted September 5, 2009 #include <Array.au3> Dim $replace[26][2] = [["a", "n"], ["b", "o"], ["c", "p"], ["d", "q"], ["e", "r"], ["f", "s"], ["g", "t"], ["h", "u"], ["i", "v"], ["j", "w"], ["k", "x"], ["l", "y"], ["m", "z"], ["n", "a"], ["o", "b"], ["p", "c"], ["q", "d"], ["r", "e"], ["s", "f"], ["t", "g"], ["u", "h"], ["v", "i"], ["w", "j"], ["x", "k"], ["y", "l"], ["z", "m"]] $old = 'overflo' for $s = 1 to Stringlen($old) $oldN = StringLeft($old, StringLen($old) - 1) $new = StringRight($old, 1) $index = _ArraySearch($replace, $new, 0, 0, 0, 0, 1, 0) $newT = $oldN & $replace[$index][1] ConsoleWrite($newT & @CRLF) Next I have this code here from another area in the forum(not sure who sorry) and i cant wrap my head around moving further, I need to replace the entire string with the $replace references array but i cant get passed just the last letter, I started to think nesting for loops and ended up second guessing myself because i thought i maybe im over complicating things and now just stuck. any help would be greatly appreciated, thanks! ;Frank. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 5, 2009 Moderators Share Posted September 5, 2009 overflo, Overwriting your original string is overcomplicating the process - it is much easier just to create a new one. If you want to retain the substitution values that you have (a simple 13 rotary substitution) I would go about the matter in a different manner: $old = 'overflo' $new = "" For $i = 1 To StringLen($old) ; Get ASCII code of character $iAsc = Asc(StringMid($old, $i, 1)) If $iAsc < 109 Then $new &= Chr($iAsc + 13) Else $new &= Chr($iAsc - 13) EndIf ConsoleWrite($new & @CRLF) Next ConsoleWrite("Old = " & $old & @CRLF) $old = $new ConsoleWrite("New = " &$old & @CRLF) If you want to keep the array because you are going to randomise the values later, then you could use your original code like this: #include <Array.au3> Dim $replace[26][2] = [["a", "n"],["b", "o"],["c", "p"],["d", "q"],["e", "r"],["f", "s"],["g", "t"],["h", "u"],["i", "v"],["j", "w"],["k", "x"],["l", "y"],["m", "z"],["n", "a"],["o", "b"],["p", "c"],["q", "d"],["r", "e"],["s", "f"],["t", "g"],["u", "h"],["v", "i"],["w", "j"],["x", "k"],["y", "l"],["z", "m"]] $old = 'overflo' $new = "" For $s = 1 To StringLen($old) $oldN = StringMid($old, $s, 1) $index = _ArraySearch($replace, $OldN) $new &= $replace[$index][1] ConsoleWrite($new & @CRLF) Next ConsoleWrite("Old = " & $old & @CRLF) $old = $new ConsoleWrite("New = " &$old & @CRLF) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
FrankwazHere Posted September 5, 2009 Author Share Posted September 5, 2009 Melba23!!!!Overwriting your original string is overcomplicating the process - it is much easier just to create a new onethat looks fantastic, I have looked through to see whats happening here and learned my lesson, StringMid you sly devil! THANKS A MIL!looks really good. It will play a major role in a future,larger scale script I'm writing for fun.,couldn't have done it without you, not this week at least IOU!, -Overflo ;Frank. Link to comment Share on other sites More sharing options...
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