Jump to content

Array StringReplace


Recommended Posts

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]

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

How 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]

Link to comment
Share on other sites

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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...