批處理for中字符串截取必須先把循環變量代替出來才行!!!

@echo off & setlocal enabledelayedexpansion
  set ifo=abc,def,ghi,jkl,mnopqrstuvwxyz0123456789
  echo 原字符串(第二行爲各字符的序號):
  echo %ifo%
  echo.
  echo 截取前5個字符:
  echo %ifo:~0,5%
  echo 截取最後1個字符:
for /f "delims=," %%a in ("%ifo%") do (
set x=%%a
echo !x!
set y=!x:~-1!
echo !y!
)
pausespa

相關文章
相關標籤/搜索