Computing.Net > Forums > Programming > extract part of a string to a var

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

extract part of a string to a var

Reply to Message Icon

Name: timothy_aah
Date: July 14, 2008 at 16:49:03 Pacific
OS: xp/vista
CPU/Ram: amd x2 4200+/2GB
Comment:

Hi,

if I run the following code:

@echo off
FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "DAEMON Tools"') DO set string=%%B
echo %string%


I get this string:

"C:\Program Files\Daemon Tools\daemon.exe" -lang 1033


how do I extract the following parts from that string?

1) "C:\Program Files\Daemon Tools\daemon.exe"

2) "C:\Program Files\Daemon Tools"

thx!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: July 14, 2008 at 17:21:13 Pacific
Reply:

You let the parser do the work for you.

@echo off
FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "DAEMON Tools"') DO CALL :parse %%B
echo %string%

GOTO :EOF
:parse
set string=%~1
set string2=%~dp1


0

Response Number 2
Name: timothy_aah
Date: July 15, 2008 at 04:29:35 Pacific
Reply:

for those who already read what I just posted here, nevermind, Razor2.3 is right, th following script gets me what I wanted:

@echo off
FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "DAEMON Tools"') DO CALL :parse %%B
echo %string%
echo %string2%

pause
GOTO :EOF

:parse
set string=%~1
set string2=%~dp1


thx for your help!

note that the delimiter gets screwed up when posting this code, it's supposed to be "tab-space", without the hyphen and the quotes of course...
computing.net removes the tab, so if you just copy and paste it, it will not work ;-)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Newbie creating a batch f... Concatenating files using...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: extract part of a string to a var

Batch Extracting part of a string www.computing.net/answers/programming/batch-extracting-part-of-a-string/15641.html

How to extract a substring after a www.computing.net/answers/programming/how-to-extract-a-substring-after-a-/18147.html

How to convert string to a binary www.computing.net/answers/programming/how-to-convert-string-to-a-binary/839.html