how to delete a element from a list

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

set a 'bolt cbar 7mm up'

#how to delete cbar from this list

lremove  command is working  when written directly in the command window but while executing as a procedure it is not executing.

Answers

  • tinh
    tinh Altair Community Member
    edited October 2017

    set a [lreplace $a 1 1]

     

     

    you can redefine lremove proc like this (to use outside of hyperworks scope):

    proc ::lremove args {

          set list [lindex $args 0]

          set ritems [lrange $args 1 end]

          #set result [lmap item $list {if {[lsearch -exact $ritems $item]==-1} {set item} else continue}]

          set result {}

          foreach item $list {

                if {[lsearch -exact $ritems $item]==-1} {lappend result $item}

          }

         set result

    }

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited October 2017

    hi tinh,

    thank you for your support. like I solved this issue by

    set a 'bolt cbar 7mm up'

    set a [lremove $a cbar]

    puts $a

    bolt 7mm up

    now this was working...