How can I remove white space from this string or replace space with ;
in batch?
ECHO V00000023903507 92 30573185 E28FC1 2015079 18-04-2015 27-04-2015 >> %EXT%
I want it to look like this:
ECHO V00000017495345;90;30485020;FD2ECC;2015079;08-04-2015;19-04-2015 >> %EXT%
You could use delayed expansion and a for
loop.
@echo off
setlocal enabledelayedexpansion
set "str= V00000023903507 92 30573185 E28FC1 2015079 18-04-2015 27-04-2015 "
set "fixed="
for %%I in (%str%) do (
if not defined fixed (set "fixed=%%I") else set "fixed=!fixed!;%%I"
)
>>outfile.txt echo %fixed%
Or you could use variable substring substitution.
@echo off
setlocal
set "str= V00000023903507 92 30573185 E28FC1 2015079 18-04-2015 27-04-2015 "
rem // replace tab with space (the blank character after : is a tab)
set "str=%str: = %"
rem // replace all multiple spaces with single
set "str=%str: = %"
rem // replace all spaces with ;
set "str=%str: =;%"
rem // remove first and last character
set "str=%str:~1,-1%"
>> outfile echo %str%
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다