bat 批處理 字串 替換函數 和 字串截取函數

來源:互聯網
上載者:User
、字串替換 好了,符號說到這,現在說%PATH:str1=str2% 上面文法的意思就是:將字串變數%PATH%中的str1 替換為str2

@echo off
@color 02
set ALL=demo123

echo %ALL%
set VAT=%ALL:1=aaa%
echo %VAT%

---結果是demoaaa23
pause

2、字串截取 ********************************************** 截取功能統一文法格式為:%a:~[m[,n]]% **********************************************
從第m為截取n長度的字串,m 為位移量(預設為0),n 為截取長度(預設為全部),n可以是負數

%a:~0,n% 相當於函數 left(a,n)   取左邊 n 位 %a:~-m%   相當於函數 right (a,m) 取右邊 m 位 %a:~m,n% 相當於函數 mid(a,m+1,n) 從 m+1 位開始取 n 位 %a:~m,-n% 相當於函數 mid(a,m+1,len(a)-m-n),從 m+1 位開始,至倒數 n+1 位 %a:~m %   相當於函數 mid(a,m+1,len(a)-m) 或者 right(a,len(a)-m),從m+1 位開始取右邊全部。

%a:~[m[,n]]%

%123:~0,1%

結果1

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.