1. 程式人生 > >批處理for中字符串截取必須先把循環變量代替出來才行!!!

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

led ims nbsp echo cal set delayed ansi abc

@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!
)
pause

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