1

I have found a way to remove text from my file, like:

set text=!text:^"~JP~"=!

removes the text ~JP~. This works good, as long ther are no functional character to remove. Now I have the character → (shown as arrow to the right, ASCII code 22, hex 1A)-

set text=!text:^"→  "=!

Results in an error (and some beep's). The line is split into

set text=!text:^"
"=!

Is there a way to do that? Like compare text to the hex-code 22 1A 09 22 (22=", 1A=→, 09=tab)?

brimborium
  • 8,880
  • 9
  • 46
  • 73

2 Answers2

3

As jeb explained in his answer, the batch parser converts 0x1A into a line feed, but the search and replace can be performed if variables are used. Here is an example of what jeb was talking about. I've embedded the string (in hex code) 0x1A 0x09 in the batch file. I use FOR /F with FINDSTR to get the value into a FOR variable. Everything after that is fairly straight forward.

@echo off
setlocal enableDelayedExpansion
:::→    :
for /f "delims=:" %%A in ('findstr "^:::" "%~f0"') do (
  set "text=abc"%%A"def"
  set text
  set "text=!text:"%%A"=!"
  set text
)

And here are the results:

text=abc"→      "def
text=abcdef

I did not include the quotes witin the embedded text because everything after the must be valid syntax. The tab and colon are harmless, but a quote would lead to a syntax error.

The behaviour of 0x1A behaving like a line feed can be useful. That is the mechanism I used to solve: Is it possible to embed and execute VBScript within a batch file without using a temporary file?

Community
  • 1
  • 1
dbenham
  • 119,153
  • 25
  • 226
  • 353
1

You can even replace characters like 0x1A, but this character is a bit problematic, as it will be converted into a linefeed while parsing the batch file.

But using a variable with the content of 0x1A will work.

jeb
  • 70,992
  • 15
  • 159
  • 202