@echo off
Setlocal ENABLEDELAYEDEXPANSION
::查找字符在字符串中最后出现的位置
set strchrR_str_str1=This is a test string
set strchrR_str_ch1=t
::注意,这里是区分大小写的!
set strchrR_str_num=0
set strchrR=0
set strchrR_str=%strchrR_str_str1%
::复制字符串,用来截短,而不影响源字符串
:next
if not “%strchrR_str%”"" (
set /a strchrR_str_num+=1
if “!strchrR_str:~0,1!”"%strchrR_str_ch1%" (
set /a strchrR=strchrR_str_num
)
set “strchrR_str=%strchrR_str:~1%”
goto next
)
echo 字符’%strchrR_str_ch1%'在字符串"%strchrR_str_str1%"中的最后出现位置为%strchrR%
echo 输出完毕,按任意键退出&&pause>nul