「ntuser.dat ntuser.dat.log ntuser.ini test.bat test1.bat advice.20131024.98767 textdoc.txt」の
ような文字列があります。指定された文字列から「advice.20131024」までのすべての文字を削除したいのですが、
どうすればよいですかWindowsバッチコマンドを使用してこれを行いますか?
結果の文字列を変数に保存する必要もあります
事前に感謝します
2276 次
2 に答える
4
これは文字列を設定し
、最後まですべてを削除するように変更し、それadvice
を置き換えてadvice
から、文字列の残りをエコーします。
set "string=ntuser.dat ntuser.dat.log ntuser.ini test.bat test1.bat advice.20131024.98767 textdoc.txt"
set "string=%string:*advice=advice%"
echo "%string%"
于 2013-10-24T11:15:50.550 に答える
1
(a) 文字列で検索する
set text=ntuser.dat ntuser.dat.log ntuser.ini test.bat test1.bat advice.20131024.98767 textdoc.txt
:loop
if "%text:~0,6%"=="advice" goto exitLoop
set text=%text:~1%
goto loop
:exitLoop
echo %text%
(b) for ループあり
@echo off
setlocal enableextensions enabledelayedexpansion
set text=ntuser.dat ntuser.dat.log ntuser.ini test.bat test1.bat advice.20131024.98767 textdoc.txt
set result=
for %%f in (%text%) do (
set x=%%f
if "!x:~0,6!"=="advice" (
set result=%%f
) else (
if not "!result!"=="" set result=!result! %%f
)
)
echo %result%
(c) foxidrive の回答を参照してください (私はいつもそれを忘れています)
于 2013-10-24T11:14:59.683 に答える