Sign in to follow this  
Followers 0
FrankwazHere

Nested for loop?

3 posts in this topic

#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. 

Share this post


Link to post
Share on other sites



overflo,

Overwriting your original string is overcomplicating the process - it is much easier just to create a new one. :D

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba23!!!!

Overwriting your original string is overcomplicating the process - it is much easier just to create a new one

that 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 :D

IOU!, -Overflo


;Frank. 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0