Replace spaces with %20 in device names in groovy?


(Chrisb) #1

Is there a way to replace spaces in a device’s display name with %20 for purposes of including them in an http string?

For example, I have a device called “Kitchen Light”. Accordingly if I do something like

log.trace "${device.displayName}"

The simulator will correctly return: Kitchen Light. But what I want is Kitchen%20Light. This way I can drop that into a url. If I do it “as is” I get an error because of the space.


(Convinced ST will never be unbroken…) #2
def toReplace = device.displayName
def replaced = toReplace.replaceAll(' ', '%20')
log.debug replaced

(Chrisb) #3

Perfect!! Thanks much @scottinpollock