把多行文本拼接成用连接的一行 ,楼主可以参考如下代码。
方法1 :
@echo off
:: 把多行文本拼接成用;连接的一行
:: <nul 不能省略,省略掉就无法运行下去
for /f "tokens=*" %%i in (源文件.txt) do set /p "var=%%i;" <nul >>目标文件.txt
exit
方法2 :
set tmpstr=
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (1.txt) do set tmpstr=!tmpstr! %%i
echo %tmpstr%
pause
exit
方法3 :
还有一种不启用变量延迟的方法,能兼容除英文双引号外的所有特殊字符:
@echo off
:: code by jm 2006-12-14
for /f "delims=" %%i in (1.txt) do call set "var=%%var%%%%i"
echo "%var%"
pause
@echo off
for /f "delims=U" %%i in ('cmd /u /c echo 唉') do set "tab=%%i"
setlocal enabledelayedexpansion
(for /f "delims=" %%i in (a.txt) do (
if defined str (
echo,!str!%tab%%%i&set "str="
) else set "str=%%i"
)
if defined str echo !str!
)>处理后.txt
pause