[Dart] NULL-CHARACTER removal

Sebastien BARRE sebastien at barre.nom.fr
Wed, 16 Jan 2002 10:08:16 -0500


At 1/16/2002 09:28 AM, Brad King wrote:
>the Tcl string handling mechanism in Tcl 8.0 and before couldn't handle
>null-bytes, but 8.1 and after could.  I'm pretty convinced that this is
>the problem.  I can put in a check for Tcl version that disables the
>replacement, but do you know of a way to do it for older Tcl versions?

I would say with 'string map', but it does not exist in Tcl 8.0

This seem to work on my Cygwin Tcl 8.0

proc clean_null_char {str} {
     set res ""
     set len [string length $str]
     for {set i 0} {$i < $len} {incr i} {
         set char [string index $str $i]
         if {$char != "\0"} {
             append res $char
         }
     }
     return $res
}

puts [clean_null_char "ab\0cd"]

barre [511] /d/temp$ cygtclsh80.exe yo.tcl
abcd


And yes, it's going to be *slow*