Replacing strings in table items

TB.ReplaceChars() is a very powerful function that scan a table and replaces any occurancies of a string with another. The process can optionally be fully recursive.

Function TB.TEST_ReplaceChars()
  Local table = { { name = "Spiderman", power = "Web" },
                  { name = "Thor", power = "Hammer" },
                  { name = "Flash", power = "Speed" },
                  { name = "Iron Man", power = "Armour" },
                  { name = "Iron Man", power = "Weapons" },
                  { name = "Hulk", power = "Strenght" } }
                  
  NPrint("TABLE CONTENT")
  For i = 0 To 5
    Local v = table[i]
    NPrint("INDEX : [color=#red]" .. i .. "[/color], NAME : [color=#yellow]" .. v.name .. "[/color], POWER : " .. v.power)
  Next

  NPrint("\nLOCATING AND REPLACING ALL <man> WITH <woman>")
  TB.ReplaceChars(table, "man", "woman", True, False)
  
  NPrint("\nTABLE CONTENT")
  For i = 0 To 5
    Local v = table[i]
    NPrint("INDEX : [color=#red]" .. i .. "[/color], NAME : [color=#yellow]" .. v.name .. "[/color], POWER : " .. v.power)
  Next
  
  NPrint("\nLeft mouse to QUIT.")
  
  WaitLeftMouse()
  
EndFunction
hollywoodlibs/tables/testreplacechars.txt · Ultima modifica: 2016/10/21 09:25 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0