Forum Discussion

Humair_167681's avatar
Humair_167681
Icon for Nimbostratus rankNimbostratus
Apr 14, 2015

String map help

Hi all,

 

Could you please explain the difference between the two commands below?

 

HTTP::uri [string map "/$customer/ /" [HTTP::uri]]

 

HTTP::uri [string map {"/$customer/" "/"} [HTTP::uri]]

 

Thanks.

 

  • I believe they are functionally equivalent. But, the second command is expressly setting the correct type for the mapping parameter. Most likely is that TCL is seeing you are passing in a string in the first command and trying to coerce it to an list of search/replace strings which that parameter is supposed to represent. Since you have a space in that string, it's convering it to the equivalent of 2.

    In an example with the TCL interpreter (tclsh), here's something similar:

    % set s 123456
    123456
    % string map {1 a} $s
    a23456
    % string map "1 a" $s
    a23456
    

    -Joe

  • Thanks Joe,

     

    Can you please elaborate "the second command is expressly setting the correct type for the mapping parameter"?

     

    Sorry - I don't seem to understand what you mean there.

     

    Regards,

     

    Humair