0

这是我的问题。我做了一批,想从句子中移动单词之间的所有空格。我以一种方式做到了这一点。但我想将空间设置为变量,并在 set 命令中使用该变量。在检查了变量的定义,甚至对这个空间变量进行了很好的回响之后,我不能在最后一句中移动它。有人可以告诉我为什么吗?

@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
4

2 回答 2

1

请看我的例子:

@echo off&setlocal
set "space= "
set "sentence=this is a long sentence with many words "

setlocal enabledelayedexpansion
set "sentence=!sentence:%space%=!"
echo "%sentence%"
于 2013-04-09T22:29:02.023 回答
0

如果你正在运行一个常规批次,只要你有“”围绕它,你应该能够做“句子”。系统应该进入一个空格

于 2013-05-08T21:22:24.880 回答