windows 如何在命令提示符下从输入字符串中提取子字符串[已关闭]

whhtz7ly  于 2022-11-18  发布在  Windows
关注(0)|答案(1)|浏览(134)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
11天前关闭。
Improve this question
我有以下字符串

set var="/host=the_host/core-service=vault:add(vault-options=[("KEYSTORE_URL" => "C:\wildfly-15.0.1.Final\bin\vault\vault.keystore"),("KEYSTORE_PASSWORD" => "MASK-18BzezESSkb72WrhEf6Rsu"),("KEYSTORE_ALIAS" => "vault"),("SALT" => "1234abcd"),("ITERATION_COUNT" => "120"),("ENC_FILE_DIR" => "C:\wildfly-15.0.1.Final\bin\vault/")])"

我想使用Windows批处理只提取MASK-18BzezESSkb72WrhEf6Rsu值。我已经尝试使用**for**,但无法找到单独提取密码的任何内容。

5t7ly7z5

5t7ly7z51#

@ECHO OFF
SETLOCAL

SET "string=/core-service=vault:add(vault-options=[("KEYSTORE_URL" => "C:\wildfly-8.2.1.Final\bin\vault\vault.keystore"),("KEYSTORE_PASSWORD" => "MASK-18BzezESSkb72WrhEf6Rsu"),("KEYSTORE_ALIAS" => "vault"),("SALT" => "1234abcd"),("ITERATION_COUNT" => "120"),("ENC_FILE_DIR" => "C:\wildfly-8.2.1.Final\bin\vault/")])"

SET "string=%string:"=%"
SET "string=%string:>=%"
SET "string=%string:<=%"
SET "string=%string:)=%"
SET "string=%string:(=%"

SET "password="

FOR %%e IN (%string%) DO IF DEFINED password (
  SET "password=%%e"
  GOTO found
 ) ELSE  IF /i "%%e"=="KEYSTORE_PASSWORD" SET "password=next"

ECHO password NOT found
GOTO :eof

:found
ECHO password is "%password%"

GOTO :EOF

使用字符串替换删除不方便的字符,然后遍历剩下的单词列表,如果找到单词before中的字符串,则将password设置为标志,并获取下一个。

相关问题