Batch Script Remove Space from Text Field.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rajnishjc_27
Posts: 17
Joined: 16 Aug 2019 23:35

Batch Script Remove Space from Text Field.

#1 Post by Rajnishjc_27 » 21 Aug 2019 23:05

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.

Szecska
Posts: 8
Joined: 15 Aug 2019 15:29
Location: Hungary

Re: Batch Script Remove Space from Text Field.

#2 Post by Szecska » 22 Aug 2019 07:01

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 :)

Szecska
Posts: 8
Joined: 15 Aug 2019 15:29
Location: Hungary

Re: Batch Script Remove Space from Text Field.

#3 Post by Szecska » 25 Aug 2019 08:33

I found a better website with examples:https://ss64.com/nt/syntax-replace.html

Post Reply