Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement parameter de-quotation marks in BAT

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "BAT how to achieve parameters to quote", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "BAT how to achieve parameters to quote" this article.

In many cases, we need to remove quotation marks that may exist in a string, and then add our own quotation marks to make the special characters (command connector &, |, & &, |, command line parameter delimiters Space, tab, , =, characterize escape characters ^, ", variational escape%, etc.) characterize, lose a specific function, and become an integral part of a string as an ordinary character.

First, there are three simple ways to remove quotation marks from a string. Their functions are similar, but they are used in different situations and can deal with most cases.

1-1. If the string exists in the command line argument% 1, you can use% ~ 1 to remove the first pair of outer quotation marks. If there are no outer quotation marks, the string will remain unchanged.

1-2. If the string exists in the for substitution variable% I, you can use% ~ I to remove the first pair of outer quotation marks. If there are no outer quotation marks, the string will remain unchanged.

1-3. If the string exists in the environment variable% temp%, you can use% temp: "=% to remove all quotation marks. If there are no quotation marks, the string will remain unchanged.

1-4. The above three schemes can be common to each other to some extent, because as a type of variables, they can be transferred to each other through code or code fragments similar to the following:

1-4-1, for substitution variable to command line argument: call:DeQuote% I 1-4-2, environment variable to command line argument: call:DeQuote% temp% 1-4-3, command line argument to for substitution variable: for% I in (% 1) do... 1-4-4, environment variable to for substitution variable: for% I in (% temp%) do. 1-4-5, Command line parameters to environment variables: set temp=%1 1-4-6, for substitution variables to environment variables: for. Set temp=%%i

2. If the distribution of quotation marks in a string is complex, or if we have special requirements for the position where the quotation marks are removed, or if some control characters may appear in the string, you can first transfer the string to the environment variable through the corresponding method in 1-4, and process it using the following scheme or a combination of it:

2-1. You can use set var=%var:~1% to remove the first quotation mark at the beginning of the environment variable var string. If the quotation mark does not exist at the beginning of the string, the first character is removed.

2-2. You can use set% var:* "=% to remove the first quotation mark of the environment variable var string. If the quotation mark does not exist at the beginning of the string, the value of the variable will not change.

2-3. You can use set var=%var:~0,-1% to remove the last quotation mark from the end of the environment variable var string. If there is no quotation mark at the end of the fruit string, the last one can be removed.

2-4. You can use set "var=%var% to remove the last quotation mark of the var string tail of the environment variable. If there are no quotation marks at the end of the string, the environment variable will be cleared.

2-5. You can use set var=%var:~1,-1% to remove the outermost pair of quotation marks from the environment variable var string. If there are no quotation marks on the outside of the fruit string, the outer pair of characters will be removed.

2-6. You can use% var:* "= set" var=% to remove the outermost pair of quotation marks from the environment variable var string. If there are no quotation marks outside the string, a syntax error will occur.

2-7. You can use set "var=%var:" =% to remove all possible quotation marks in the environment variable var string. If the quotation marks do not appear on the outside of the string, the value of the variable will not change. Unlike 1-3, it allows the matching quotation marks of the string to appear special control characters inside.

The above is all the contents of the article "how to implement parameter quotation marks in BAT". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report