Windows   发布时间:2022-05-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Windows批处理中打印段落大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
以下代码可以很好地打印段落

@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
  'findstr /x /n ":::Begintext" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
  for /f "skip=%skip% tokens=*" %%A in (
   'findstr /n "^" "%~f0"'
  ) do (
    set "line=%%A"
    setlocal enableDelayedExpansion
    echo(!line:*:=!
    endlocal
  )
)
type test.txt
exit /b

:::Begintext
This text will be exactly preserved with the following limitations:

  1) Each line will be terminated by CR LF even if original has only LF.

  2) Lines are limited in length to approximately 8191 bytes.

Special characters like ^ & < > | etc. do not cause a problem.
Empty lines are preserved!
;Lines beginning with ; are preserved.
:::Leading : are preserved

有没有办法添加像::: Endtext这样的文本标记,以便只有段落之间的段落
  ::: Begintext和::: Endtext打印.

解决方法

当然:-)

并且您可以在脚本中嵌入多个命名段落,并通过为每个段落使用唯一标签来选择性地编写它们.

只要GOTO和/或EXIT / B阻止文本被执行,命名文本就可以出现在脚本中的任何位置.

为方便起见,下面的脚本将逻辑封装在:printParagraph例程中.

@echo off
setlocal disableDelayedExpansion
goto :start

:::Begintext1
Paragraph 1
  is preserved

Bye!
:::EndText

:start
echo Print paragraph 1 directly to screen
echo ------------------------------------------
call :printParagraph 1
echo ------------------------------------------
echo(
echo(

call :printParagraph 2 >test.txt
echo Write paragraph 2 to a file and type file
echo ------------------------------------------
type test.txt
echo ------------------------------------------
echo(
echo(

echo Print paragraph 3 directly to screen
echo ------------------------------------------
call :printParagraph 3
echo ------------------------------------------
echo(
echo(

exit /b

:::Begintext2
This is paragraph 2

Pure poetry
:::EndText

:printParagraph
set "skip="
for /f "delims=:" %%N in (
  'findstr /x /n ":::Begintext%~1" "%~f0"'
) do if not defined skip set skip=%%N
set "end="
for /f "delims=:" %%N in (
  'findstr /x /n ":::EndText" "%~f0"'
) do if %%N gtr %skip% if not defined end set end=%%N
for /f "skip=%skip% tokens=*" %%A in (
 'findstr /n "^" "%~f0"'
) do (
  for /f "delims=:" %%N in ("%%A") do if %%N geq %end% exit /b
  set "line=%%A"
  setlocal enableDelayedExpansion
  echo(!line:*:=!
  endlocal
)
exit /b

:::Begintext3
One more...

  ...for good measure
:::EndText

大佬总结

以上是大佬教程为你收集整理的在Windows批处理中打印段落全部内容,希望文章能够帮你解决在Windows批处理中打印段落所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: