MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: String Replacement[Next]: Special Characters (tabs etc)
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Tips and Tricks->SET Command->SubString Extraction

SubString Extraction

Sometimes you want to extract certain characters out of a bigger string or environment variable, this shows how it can be done:

@echo off
@rem *** Copy to "TryMe.cmd" and execute :-) ***
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cls

set   WholeString=123456789
set        Left20=%WholeString:~0,20%
set    Left4Chars=%WholeString:~0,4%
set   Right4Chars=%WholeString:~-4%
set  The3rdAnd4th=%WholeString:~2,2%
set   AllButFirst=%WholeString:~1%
set    AllButLast=%WholeString:~0,-1%

echo WholeString  = "%WholeString%"
echo.
echo Left20       = "%Left20%"       (note: wasn't padded to 20 characters)
echo Left4Chars   = "%Left4Chars%"
echo Right4Chars  = "%Right4Chars%"
echo The3rdAnd4th = "%The3rdAnd4th%"
echo AllButFirst  = "%AllButFirst%"
echo AllButLast   = "%AllButLast%"


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: String Replacement[Next]: Special Characters (tabs etc)


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Monday March 08 2010 at 12:20pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.