You are not logged in.
I'm working on a script that will have a variable set to an unknown string. Said string may contain non-ANSI characters, which I would like to convert to ANSI. This would be easy to do using their hex values, but that didn't seem to work.
A simple example;
set name=This is a test: now
set name2=%name:0x3A=0x2D%
echo %name2%
Theoretically what it should do is change the ":" to "-", however it doesn't work
Yes, I know that in this particular case, I don't need to use hex values because they're both ANSI characters, but I'm trying to develop a solution that will let me replace non-ANSI characters.
Is this possible?
Offline
There's no native interpolation of HEX into their binary values (though they can be turned into their decimal equivalent using set /a, but that's not helpful to you here).
That said, there's a script here that can do the interpolation:
https://ss64.com/nt/syntax-genchr.html
cmd | *sh | ruby | chef
Offline
There's no native interpolation of HEX into their binary values (though they can be turned into their decimal equivalent using set /a, but that's not helpful to you here).
That said, there's a script here that can do the interpolation:
https://ss64.com/nt/syntax-genchr.html
That's what I figured
I think the easiest option for me will be to just echo the variable to a temporary file and then run Gsar on it, which allows you to find/replace hex values, then read the file back into the variable. I was hoping there would a simple native Windows way to do it as I plan to include this in a script that I'm going to share with someone else and the fewer external files I need to include with it to make it work, the better.
Thanks for your reply.
Offline