Предыдущая тема :: Следующая тема |
Автор |
Сообщение |
ICU Гость
|
Добавлено: Вт Июн 22 2004 09:28 Заголовок сообщения: Переменные BAT-файлов |
|
|
Вопрос касается взятия подстрок от значений переменных в командных (batch) файлах. Как взять подстроку справа помню. Вот пример такого батника :
@set YEAR=%DATE:~-4%
:: Объявляем переменную YEAR и присваиваем ей
:: 4 правых символа от значения
:: системной переменной %DATE%
@echo %DATE%
:: Выведет текущую дату, например: 22.06.2004
@echo %YEAR%
:: Выведет текущий год, согласно примеру: 2004
А как взять подстроку справа/из середины и какие еще возможны строковые манипуляции напрочь не помню.
ЗЫ. Командный интерпритатор от вин ХР |
|
Вернуться к началу |
|
|
4u3u
Зарегистрирован: 24.01.2003 Сообщения: 997 Откуда: Moscow
|
Добавлено: Вт Июн 22 2004 09:39 Заголовок сообщения: |
|
|
"set /?" слабо набрать? :)
------------------------
Environment variable substitution has been enhanced as follows:
%PATH:str1=str2%
would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output. "str1" can begin with an asterisk, in which case it will match
everything from the beginning of the expanded output to the first
occurrence of the remaining portion of str1.
May also specify substrings for an expansion.
%PATH:~10,5%
would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result. If the length is not specified, then it defaults to the
remainder of the variable value. If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.
%PATH:~-10%
would extract the last 10 characters of the PATH variable.
%PATH:~0,-2%
would extract all but the last 2 characters of the PATH variable.
------------------------ |
|
Вернуться к началу |
|
|
4u3u
Зарегистрирован: 24.01.2003 Сообщения: 997 Откуда: Moscow
|
Добавлено: Вт Июн 22 2004 09:40 Заголовок сообщения: |
|
|
Да, кстати, это не "переменные бат-файлов", а переменные окружения. |
|
Вернуться к началу |
|
|
|