Monday, November 21, 2011

Delete element from List

Deleting element from list-Element can be deleted from list using silktest ListDelete function

ListDelete(List of string, index)

However if you want to delete by name then here is the sample code

LIST OF STRING lString = {"Apple", "Orange", "Mango", "Guava"}
int i= 1
LIST OF STRING temp = {...}
while(i <= ListCount(lString)
  if lString[i] = "Mango"
      ListDelete(lString, i)
  else
     ListAppend(temp, lString[i])
      i++
print(temp)


// Delete duplicate element from list

 [ ] LIST OF STRING ls = {"11", "33", "44", "55", "33", "88", "33"}
 [ ] List of STRING temp = {...}
 [ ] int i=1, j, count = 0
 [-] for j = 1 to listcount(ls)
  [-] if ls[j] == "33"
   [ ] count = count + 1
 [ ] 
 [-] while(i <= listcount(ls))
  [ ] 
  [-] if (ls[i] == "33" && count >> 1)
   [ ] listdelete(ls, i)
   [ ] count --
  [-] else
   [ ] listappend(temp, ls[i])
   [ ] i++
  [ ] 
 [ ] print(temp)

No comments:

Post a Comment