LoginSignup
3
4

More than 3 years have passed since last update.

Windows バッチファイルで変数の中の文字列を置換する

Posted at

目的

  • バッチファイルやコマンドプロンプトで変数に格納された文字列を置換する方法を書く。

書き方の例

  • 変数には任意の文字列が格納されているものとする。
  • 下記に変数に格納された文字列を置換して表示する処理を記載する。
echo %変数名:置換対象の文字列=置換後の文字列%

より具体的な例

  • 変数stringには文字列「aaabbbccc」が格納される。
  • 変数stringの「aaa」を「bbb」に置換して出力する処理を記載する。
REM [変数の定義と値の格納]
set string=aaabbbccc

REM [変数内文字列の置換と出力]
echo %string:aaa=bbb%
>bbbbbbccc
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4