Stringbuilder usage of "delete"

my stringbuilder rule appends a string to a var each time the rule triggers.
but how do I delete the var at the begin of the rule so the string is always build from scratch?
I tried test.clear, test.delete, test = “”, test = null… all without success

var test = new StringBuilder

rule " test1"  
        when    
                Item vSwitch1 changed 
        then 
                gIPdevices.members.filter[ k | k.state == ON ].forEach[k | test.append(k.name + "%20und%20") ]
                logInfo("var rules", "IP Devs" + test)

Unless you have a particular need for the variable to be a “global”, move your declaration inside your rule.

        then 
                val test = new StringBuilder
                gIPdevices.members.filter[...

I think you may need to use val in this usage.

@rossko57 is absolutely right. But for those who come along later and really do need to clear out a StringBuilder, use .clear(). Given the nature of OH rules, I can’t imagine this would need to be done except in very unusual circumstances so if you find yourself wanting to clear, refer to rossko57’s post.