Table of Contents

DOS - String Variable

About

Text - String data type in DOS

Manipulation

Replace

When you want to use the time, you will get colon that you can't use in a file name. To overcome this problem, you can replace the colon with an underscore.

set theTime=%time%
echo theTime
15:04:31.11

:: Replace : with _
echo %theTime::=_%
15_04_31.11

Slice

The slice operation syntax is:

%myVariable:~indexFirst,numberOfLetters %

where:

Example:

set theTime=%time%
echo %theTime%
15:12:16.36

echo %theTime:~3,2%
12
echo %theTime:~,-3%
15:12:16

echo %theTime:~3%
12:16.36

echo %theTime:~-3%
.36

Comparison

See text and number comparison