SET java_path =“C:\ Program Files \ Java \ jdk1.6.0_31”
上面是我的字符串,我只想要来自java_path的“C:\ Program Files”。怎么弄明白?
答案 0 :(得分:2)
试试这个:
@ECHO OFF &SETLOCAL
SET "java_path=C:\Program Files\Java\jdk1.6.0_31"
SET "this=%java_path:~3%"
SET "this=%this:*\=%"
CALL SET "this=%%java_path:%this%=%%"
SET "this=%this:~0,-1%"
ECHO %this%
答案 1 :(得分:1)
您可以按字符位置分割字符串:
ECHO %java_path:~1,16%
或通过拆分特定字符:
FOR /F "DELIMS=\ TOKENS=1,2" %i IN (%java_path%) DO ECHO %i\%j