Page 1 of 1

Batch Script Remove Space from Text Field.

Posted: 21 Aug 2019 23:05
by Rajnishjc_27
Hi Friends,

I have a data like below in .TXT file.

Id Name Address CurrierNo
001 XYX Mum M 123
002 ZZZ Bom B 456

and i have use script as below.
for /f " skip=1 tokens=4 delims=; " %%c in (%file% ) do (
setlocal enabledelayedexpansion

SET "string1=%%c" & CALL D:\Rajnish_GTT\isnumeric.bat result1 !string1!
if "!result1!" equ "N" (
echo(field "%%~c" Is Not a Numeric)
)

according to Tokens=4 should check Currier No Fields, but instead of that its considering " Mum M" because its taking space in Token.

Please help , how can i handle the space (remove) in text fields in script.

Thank you.

Re: Batch Script Remove Space from Text Field.

Posted: 22 Aug 2019 07:01
by Szecska
Hi!

You should really check out the "help set" command.
Environment variable substitution has been enhanced as follows:

%PATH:str1=str2%
would expand the PATH environment variable, substituting each occurrence of "str1" in the expanded result with "str2". "str2" can be the empty string to effectively delete all occurrences of "str1" from the expanded output. "str1" can begin with an asterisk, in which case it will match everything from the beginning of the expanded output to the first occurrence of the remaining portion of str1.
(This is from an online documentation https://www.robvanderwoude.com/ntset.php; I cant copy straigth from console because of the localisation.)

With this you can replace every space to another character/string, or even remove them with

Code: Select all

!string1: =!
I hope that helps :)

Re: Batch Script Remove Space from Text Field.

Posted: 25 Aug 2019 08:33
by Szecska
I found a better website with examples:https://ss64.com/nt/syntax-replace.html