Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
  • How to split string using batch script?

SET java_path="C:\Program Files\Java\jdk1.6.0_31"

above is my string, i want only "C:\Program Files" from java_path. how to get it?

share|improve this question

2 Answers

up vote 1 down vote accepted

You may split strings by character position:

ECHO %java_path:~1,16%

or by splitting at specific characters:

FOR /F "DELIMS=\ TOKENS=1,2" %i IN (%java_path%) DO ECHO %i\%j

share|improve this answer

try this:

@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%
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.