Touch Posted July 12, 2008 Posted July 12, 2008 Hello! How do I go about replacing data in an array? Let's say I have: $Array[3][2] = [["o", "0"], ["100", "1"], ["two", "2"]] How do I make a function to replace the o, 100 and two with the normal, 0, 1 and 2? Touch [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]
Developers Jos Posted July 12, 2008 Developers Posted July 12, 2008 Just do a For-Next loop processing all Array entries with a StringReplace(). muttley SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
AdmiralAlkex Posted July 12, 2008 Posted July 12, 2008 another possible way; #include "Array.au3" Global $Array[3][2] = [["o", "0"], ["100", "1"], ["two", "2"]] _ArrayDisplay($Array) For $A = 0 To UBound($Array, 1)-1 For $B = 0 To UBound($Array, 0)-1 Switch $Array[$A][$B] Case "o" $Array[$A][$B] = 0 Case "100" $Array[$A][$B] = 1 Case "two" $Array[$A][$B] = 2 EndSwitch Next Next _ArrayDisplay($Array) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
newbiescripter Posted July 12, 2008 Posted July 12, 2008 In this case you could also just do like this: #Include <Array.au3> Global $Array[3][2] = [["o", "0"], ["100", "1"], ["two", "2"]] _ArrayDisplay($Array) For $i=0 to UBound($Array,1) - 1 $Array[$i][0] = $i Next _ArrayDisplay($Array) It doesn't look for the String in the Array first so it just replace it with the same numbers as in the first dimension of the array, but I wasn't sure what you want.. Regards
Touch Posted July 12, 2008 Author Posted July 12, 2008 In this case you could also just do like this: #Include <Array.au3> Global $Array[3][2] = [["o", "0"], ["100", "1"], ["two", "2"]] _ArrayDisplay($Array) For $i=0 to UBound($Array,1) - 1 $Array[$i][0] = $i Next _ArrayDisplay($Array) It doesn't look for the String in the Array first so it just replace it with the same numbers as in the first dimension of the array, but I wasn't sure what you want.. RegardsHow do I go about expanding this so that it returns the final result? [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]
Touch Posted July 12, 2008 Author Posted July 12, 2008 I have this so far: Func Convert($string, $farray) For $i = 0 To UBound($farray, 1) - 1 $OutString = StringReplace($string, $farray[$i][0], $farray[$i][1]) Next Return $OutString EndFunc ;==>Convert But it returns the same value? [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]
Touch Posted July 12, 2008 Author Posted July 12, 2008 For $i = 0 To UBound($farray, 1) - 1 $String = StringReplace($string, $farray[$i][0], $farray[$i][1]) Next Return $String Only returns 1 character from each array value. [center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]
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