You are not logged in.

#1 28 Nov 2019 07:03

Rekrul
Member
Registered: 17 Apr 2016
Posts: 98

Substring search/replace: Possible to use hex values?

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

#2 28 Nov 2019 12:50

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Substring search/replace: Possible to use hex values?

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

#3 28 Nov 2019 14:15

Rekrul
Member
Registered: 17 Apr 2016
Posts: 98

Re: Substring search/replace: Possible to use hex values?

bluesxman wrote:

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. smile

Offline

Board footer

Powered by