Remove a key and its associated value from a Map.
MapRemove ( map, key )
map | An existing Map |
key | The key to remove |
Success: | 1 |
Failure: | 0 and sets the @error flag to non-zero |
Almost uniquely in AutoIt, keys are case sensitive - "MyKey" is not the same as "mykey"
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Declare a map and assign with various keys value pairs.
Local $mMap[]
$mMap["Jasper"] = "Jasper value"
$mMap["Beethoven"] = "Beethoven value"
$mMap["Pinky"] = "Pinky value"
; Read keys
Local $aKeys = MapKeys($mMap)
Local $sData = ""
; Read values
For $i = 0 To UBound($aKeys) - 1
$sData &= $aKeys[$i] & ": " & $mMap[$aKeys[$i]] & @CRLF
Next
; Display result
MsgBox($MB_SYSTEMMODAL, "", $sData & @CRLF & _
'Beethoven exists: ' & MapExists($mMap, "Beethoven") & @CRLF & 'Beethoven equals Null: ' & ($mMap["Beethoven"] == Null))
; Clear a key by setting it to Null. The key will still exist in the map.
$mMap["Beethoven"] = Null
; Re-read keys and values
$aKeys = MapKeys($mMap)
$sData = ""
For $i = 0 To UBound($aKeys) - 1
$sData &= $aKeys[$i] & ": " & $mMap[$aKeys[$i]] & @CRLF
Next
; Display the values of the map keys. Notice how the "Beethoven" key now contains an empty value (Null).
MsgBox($MB_SYSTEMMODAL, "", $sData & @CRLF & _
'Beethoven exists: ' & MapExists($mMap, "Beethoven") & @CRLF & 'Beethoven equals Null: ' & ($mMap["Beethoven"] == Null))
; Remove the "Beethoven" key entirely.
MapRemove($mMap, "Beethoven")
; Re-read keys and values
$aKeys = MapKeys($mMap)
$sData = ""
For $i = 0 To UBound($aKeys) - 1
$sData &= $aKeys[$i] & ": " & $mMap[$aKeys[$i]] & @CRLF
Next
; Display the values of the map keys. Notice how the "Beethoven" key is no longer exists.
MsgBox($MB_SYSTEMMODAL, "", $sData & @CRLF & _
'Beethoven exists: ' & MapExists($mMap, "Beethoven") & @CRLF & 'Beethoven equals Null: ' & ($mMap["Beethoven"] == Null))
EndFunc ;==>Example