Reputation: 29
here is my problem. I make a batch and want to move all spaces between words from sentence. I did this on one way. But i want to set space as variable, and use that variable in set command. After cheking definition of variable, and even good echoing of this space variable, i cannot move it in last sentence. Somebody can tell me why?
@echo off
::why this doesnt work???
(set /p word2=i will make )<nul>textfile.txt
<nul (set/p word3=all strings be )>>textfile.txt
<nul (set/p word4=one longstring)>>textfile.txt
echo(
type textfile.txt
echo(
echo(
::seting space
set sp=a b
set sa=%sp:a=%
set space=%sa:b=%
if defined space (echo space is defined) else (echo space is not defined)
echo(
echo lets see:%space%%space%%space%something%space%something%space%%space%, ...works
echo(
set /p inputalltext=<textfile.txt
echo %inputalltext%...input from textfile
set noplaceforspace=%inputalltext: =% ...as you see as normal,no space
echo %noplaceforspace%
::so, problem starts here. why are here places if space is defined and good echoing
::of space variable??
setlocal enabledelayedexpansion
set nogoodresult=%inputalltext:!space!=%
echo %nogoodresult%%space%%space% here i dont want space between words
echo(
pause
Upvotes: 0
Views: 199
Reputation: 335
if you are running a regular batch you should be able to do "sentence sentence" as long as you have the"" around it. the system should enter a space
Upvotes: 0
Reputation: 37569
Please look at my example:
@echo off&setlocal
set "space= "
set "sentence=this is a long sentence with many words "
setlocal enabledelayedexpansion
set "sentence=!sentence:%space%=!"
echo "%sentence%"
Upvotes: 1