hi all,
is it possible to set a string that has a backward slash in it like this?
set str "d:\drive\"
it's not accepting. but I have to use this \ in my string. wat shud I do?
regards.
well anyways, I declared it this way.
set string1 [format "%s" "d:\exchange\"]
regsub -all {/} $string1 {\\} string2
I hope there shud be a better way.
Rajverma.
That won't work. The regsub statement changes "/" to "\". In order to set the string the way you want you need double slashes "\\". Tcl interprets the first "\" as the escape sequence designator. "\\" is expanded to a literal "\".
As ulis pointed out, if you're going to be passing these path references to Tcl commands, you don't need to convert from "/" to "\". Here's what the Tcl filename reference page has to say on the subject:
"All Tcl commands and C procedures that take file names as arguments expect the file names to be in one of three forms, depending on the current platform. On each platform, Tcl supports file names in the standard forms(s) for that platform. In addition, on all platforms, Tcl supports a Unix-like syntax intended to provide a convenient way of constructing simple file names. However, scripts that are intended to be portable should not assume a particular form for file names. Instead, portable scripts must use the file split and file join commands to manipulate file names (see the file manual entry for more details)."
And for those instances where you really do need to convert to your platform's native version of a path (for example, displaying a path to a user, writing it into a file that might be read by other programs, etc.), use the file nativename command.
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting,
hi all, I'm v v sorry for the confusion. Actually I wanted to use "\" in my string(eg: set string "d:\exchange\xxx" ) to pass it to a windows machine, but it's not working. so I did this way.
I did a mistake in my first question, where I said that I used,
set string1 [format "%s" "d:\exchange\xxx"]
regsub -all {/} $string1 {\\} string2.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.