PSP
PSP

Reputation: 11

Unable to read pipe character in batch file

I want to replace underscore(_) with space( ) form the string. But the batch I have written can't read the pipe(|) character. I tried putting (^) character before every PIPE but it did not work. Below is the script I tried.

@ECHO OFF
set string=Transaction_Type|Spend_Source_System|Event_ID
set string1=Transaction Type|Spend Source System|Event ID
set string=%string1%
ECHO %string%
pause

Upvotes: 1

Views: 90

Answers (3)

jeb
jeb

Reputation: 82307

I recommend the first part of foxidrive's solution, but for the output, I would use delayed expansion, as you don't need quotes around the string anymore.

@ECHO OFF
setlocal EnableDelayedExpansion
set "string=Transaction_Type|Spend_Source_System|Event_ID"
set "string=!string:_= !"
echo !string!

Upvotes: 0

Magoo
Magoo

Reputation: 80033

@ECHO OFF
SETLOCAL
set "string=Transaction_Type^|Spend_Source_System^|Event_ID"
set "string1=Transaction Type^|Spend Source System^|Event ID"
set "string=%string1%"
ECHO %string%
endlocal
SETLOCAL
set "string=Transaction_Type^|Spend_Source_System^|Event_ID"
set "string=%string:_= %"
ECHO %string%

GOTO :EOF

Yeah - 'tis a little tricky...

Upvotes: 0

foxidrive
foxidrive

Reputation: 41244

Try this:

@ECHO OFF
set "string=Transaction_Type|Spend_Source_System|Event_ID"
set "string=%string:_= %"
ECHO "%string%"
pause

Upvotes: 2

Related Questions