Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Partial strings in batch/command line scripting...

Status
Not open for further replies.

Dimarc67

MIS
Feb 23, 2004
69
US
There is an ability to return a partial string from an environment variable in batch programming, but I've been unable to find any reference to it on the net.

This is the standard usage of an environment variable:

C:\>echo %DATE%
Fri 08/19/2005

But, from a quick clue offered on an old post out on the net, I've learned that following the variable's name with a colon and tilde (":~") and a number, you can specify a number of characters to be dropped from the left end of the string. Hence:

C:\>echo %DATE:~4%
08/19/2005

Place a minus sign in front of the number, and you're now specifying the number of characters to use from the right end of the string:

C:\>echo %DATE:~-10%
08/19/2005

That's as much as I've been able to glean with trial and error. I can't find any documentation on this, neither on the internet, nor in the MS help files and knowledge base, though I can't be certain that I'm searching for the correct terms.

Does anyone have any information on this? Ultimately, I'm hoping there's an ability to specify the number of characters from the left end of the string that I'd like returned instead of dropped.

David Marcus
New York, NY
 
Open a command prompt and type

SET /? <RETURN>

Using the information in here, you can return the middle of the string. This technique has worked at least since Windows 2000.

John
 
Thank you! Knew it had to be somewhere easy, just couldn't find the right terminology to search for...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top