[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 【已解决】批处理如何在每一行的开头和结尾随机添加AA BB CC其中一个?

本帖最后由 elec 于 2014-7-7 23:44 编辑

假设一个文本为
  1. square cake board, 6 cocktail sticks,
  2. 200g giant milk chocolate buttons,
  3. 15 yellow or orange boiled sweets,
  4. 2 night lights. When people reach
  5. middle age, the gel like vitreous begins
  6. to liquefy and contract. The vitreous
  7. gel pulls away from the back
  8. wall of the eye, causin
复制代码
我想在文本的前后随机加入<br /><br />    <b></b>    <body></body> 其中一种形式

如下是其中一种可能
  1. <b>square cake board, 6 cocktail sticks,</b>
  2. <body>200g giant milk chocolate buttons,</body>
  3. <br />15 yellow or orange boiled sweets, <br />
  4. <b>2 night lights. When people reach</b>
  5. <body>middle age, the gel like vitreous begins </body>
  6. <b>to liquefy and contract. The vitreous </b>
  7. <br />gel pulls away from the back <br />
  8. <br />wall of the eye, causin<br />
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

看你发了那么多贴,已经解决的至少标注下已解决吧,即方便后来者,也尊重下帮你解决问题的人。
初学BAT,非专业。代码不适当之处还望前辈们多多指点。在此表示感谢!

TOP

2楼说的对!

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set arr00=^<b^>
  4. set arr01=^</b^>
  5. set arr10=^<br /^>
  6. set arr11=^<br /^>
  7. set arr20=^<body^>
  8. set arr21=^</body^>
  9. (for /f "delims=" %%i in (new.txt) do (
  10. set /a num=!RANDOM!%%3
  11. for %%j in (!num!) do set pre=!arr%%j0! & set suf=!arr%%j1!
  12. echo !pre!%%i!suf!
  13. ))>new2.txt
  14. pause
复制代码
1

评分人数

TOP

返回列表