In addition to Nimue's fix, I'd suggest these changes as well because they say what you mean.
Code:

test {
  var %y, %x = 1, %1- = $replace($1-, $chr(32), $chr(127))
  while $mid(%1-, %x, 1) != $null {
    %y = %y $+ (- $+ $ifmatch $+ -)
    inc %x
  }
  return $replace(%y, $chr(127), $chr(32))
}

This version allows for spaces by first replacing spaces with a hard space, then reversing the process at the end.

Using the $mid() as your while condition allows you to use $ifmatch which will hold the character found. You don't need to keep recomputing $len($1-) and then comparing that to whatever %x is. If the $mid() returns a character, then you can process that character (the $ifmatch). cool If you were going to use the length of the string for something else, then using $len() would be reasonable, but you're not and don't need it. laugh

//var %text = Testing this, ok? | echo -a $testing(%text)
(-t-)(-e-)(-s-)(-t-)(-i-)(-n-)(-g-)(- -)(-t-)(-h-)(-i-)(-s-)(-,-)(- -)(-o-)(-k-)(-?-)


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C