[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 shelluserwlb 于 2014-11-17 10:27 编辑
  1. @echo off
  2. set str=今日明月在
  3. echo 修改前:%str%
  4. echo %str:~0,2% & echo.%str:~2,2% & echo.%str:~4,1%
  5. echo 修改后:%str:~2,2%%str:~0,2%%str:~4,1%
  6. pause>nul
复制代码

TOP

@echo off
set p=今日明月在
set var1=%p:~2,2%
set var2=%p:~0,2%
set var3=%p:~-1%
set sum=%var1%%var2%%var3%
echo %sum%
pause

TOP

回复 1# wxcute
@echo off
set qq=今日明月在
echo %qq%
echo %qq:~0,2%
echo %qq:~2,2%
echo %qq:~4,1%
echo %qq:~2,2%%qq:~0,2%%qq:~4,1%
pause>nul

TOP

回复 1# wxcute
@ECHO OFF
SET "VAR1=今日明月在"
SET "VAR2=%VAR1:今日明月=明月今日%"
ECHO %VAR2%

TOP

::===========================================================
::有一个 QQ 昵称为“今日明月在”,(昵称是不是很诗意呢?)
::1、请分别截取“今日”、“明月”、“在”,并显示出来。
::2、通过变量截取把 “今日明月在” 变成 “明月今日在” 显示出来。
::===========================================================
@echo off
set "qq=今日明月在"
echo %qq:~0,2%
echo %qq:~2,2%
echo %qq:~4,1%
echo %qq:~2,2%%qq:~0,2%%qq:~4,1%
pause>nul

TOP

  1. @echo off
  2. set str1=今日明月在
  3. set str2=%str1:~0,2%
  4. set str3=%str1:~2,2%
  5. set str4=%str1:~-1%
  6. echo %str2%
  7. echo %str3%
  8. echo %str4%
  9. echo %str3%%str2%%str4%
  10. pause
复制代码
我这比较笨的方法。运行会浪费资源。

TOP

  1. @echo off
  2. set qname=今日明月在
  3. set var1=%qname:~0,2%
  4. set var2=%qname:~2,2%
  5. set var3=%qname:~4,1%
  6. echo %var1%
  7. echo %var2%
  8. echo %var3%
  9. echo %var2%%var1%%var3%
  10. pause
复制代码
刚开始学,写的比较中规中矩,,看了几页帖子,发现代码还可以精简;还有很多用for循环的写法,思路真不错,学习了。

TOP

@echo off
set var=今日明月在
echo %var:~0,2%
echo %var:~2,2%
echo %var:~-1%
pause
====================================
@echo off
set var=今日明月在
echo %var:~2,2%%var:~0,2%%var:~-1%
pause

TOP

我来回帖,先看下!

TOP

  1. @echo off
  2. set str=今日明月在
  3. set var=%str:~0,3%
  4. type nul>f:\1.txt
  5. echo %str:~0,2%>f:\1.txt&&type f:\1.txt
  6. pause
  7. @echo off
  8. ::不好意思把字符分开截取FOR
  9. set str=今日,明月,在
  10. type nul>f:\2.txt
  11. set var=%str:~-4%
  12. echo %str:~-4%
  13. echo %str:~-4%>f:\2.txt&&type f:\2.txt
  14. echo var=2.txt
  15. if exist f:\2.txt (echo F盘下有2.txt存在) else (echo f盘下没有2.txt存在)
  16. for /f %%i in (f:\2.txt) do echo %%i
  17. for /f "delims=," %%i in (f:\2.txt) do echo %%i
  18. pause
  19. @echo off
  20. set str=明月,在
  21. set var=%str:~0,2%
  22. echo %str:~0,2%
  23. type nul>f:\3.txt
  24. echo %str:~0,2%>f:\3.txt&&type f:\3.txt
  25. @echo off
  26. set str=明月,在
  27. set var=%str:-1%
  28. echo %str:~-1%
  29. type nul>f:\4.txt
  30. echo %str:~-1%>f:\4.txt&&type f:\4.txt
  31. pause
  32. @echo off
  33. type f:\1.txt>>f:\3.txt
  34. type f:\4.txt>>f:\3.txt
  35. type f:\3.txt
  36. pause
复制代码
[attach]7375[/attach]
  1. @echo off
  2. ::好累
  3. pause
复制代码

TOP

本帖最后由 redwolf100 于 2014-6-25 11:46 编辑

努力练习中...
  1. @echo off
  2. cls
  3. set str=今日明月在
  4. set a=%str:~0,2%
  5. set b=%str:~2,2%
  6. set c=%str:~4%
  7. echo %a%
  8. echo %b%
  9. echo %c%
  10. echo %b%%a%%c%
  11. pause
复制代码

TOP

新手报到吗?纯新手啦~
@echo off
set str=今日明月在
set ver1=%str:~2,2%
set ver2=%str:~0,2%
set ver3=%str:~4%
echo %ver1%%ver2%%ver3%
pause>nul

TOP

@echo off
set a=今日明月在
set b=%a:~0,2%
set c=%a:~2,2%
set d=%a:~-1%
echo %b%
echo %c%
echo %d%
pause

TOP

@echo off
set str=今日明月在
set a=%str:~0,2%
echo %a%
set b=%str:~2,2%
echo %b%
set c=%str:~4%
echo %c%
set str=%str:今日明月=明月今日%
echo %str%
pause

TOP

@echo off
set str=今日明月在
set a=%str:~0,2%
echo %a%
set b=%str:~2,2%
echo %b%
set c=%str:~4%
echo %c%
pause

TOP

返回列表