VS2017 - 框架4.6.2不是在c#中的类库项目中显示的选项,但它是在一个vb窗体中的一个窗体中(VS2017 - Framework 4.6.2 is not shown as an option in a class library project in c#, but it is in a vb windows forms one)
It's the same visual studio 2017 instalation. I've already downloaded and installed the net framework 4.6.2 developer pack from here
Regards!
原文:https://stackoverflow.com/questions/50118859
最满意答案
CMD有许多具有特殊含义的字符,通常被称为“毒性字符”,因为如果它们暴露给批处理解析器,它们可能会导致许多不需要的影响。 示例包括
&
|
>
<
- 还有更多。通常,如果字符引用为
">"
,或者像^>
那样转义,则不会导致问题。 但是你无法控制用户输入的内容。 使用正常扩展时,某些值不安全。 例如,如果用户输入This & that "& the other thing"
,则无法在值周围添加引号,以便引用两个&
。值得庆幸的是,延迟扩展提供了一个简单的解 而不是使用
%VAR%
扩展变量,而是使用!VAR!
。 解析器完成查看所有字符后扩展变量,因此毒性字符不会导致任何问题。 必须首先使用setlocal enableDelayedExpansion
启用延迟扩展这是一个简单的演示,无论出现什么毒性字符,都可以成功地ECHO用户键入的任何值。 您可以轻松地将代码调整为IF语句。
@echo off setlocal enableDelayedExpansion set /p "var=Enter a string: " echo You entered: !var!
CMD has many characters that have special meaning that are often referred to as "poison characters" because they can lead to many unwanted effects if they are exposed to the batch parser. Examples include
&
|
>
<
- there are more.Generally, the characters do not cause problems if they are either quoted like
">"
, or escaped like^>
. But you don't have control over what the user enters. Some values simply are not safe to work with using normal expansion. For example, if the user entersThis & that "& the other thing"
, then there is no way to add quotes around the value such that both&
are quoted.Thankfully, delayed expansion provides a simple solution. Instead of expanding a variable using
%VAR%
, you use!VAR!
. The variable is expanded after the parser finishes looking at all the characters, so the poison characters do not cause any problem. Delayed expansion must first be enabled by usingsetlocal enableDelayedExpansion
Here is a simple demonstration that will successfully ECHO any value the user types in, no matter what poison characters are present. You can easily adapt the code to an IF statement.
@echo off setlocal enableDelayedExpansion set /p "var=Enter a string: " echo You entered: !var!
相关问答
更多-
在if语句中测试时,您没有将userinput包装在%%中,因此程序将其解释为纯文本而不是变量。 尝试: @ CLS @ set /P name="Type your name: " @ set /P userinput="Type your name again: " @ if /I "%userinput%"=="%name%" goto correct @ if /I "%userinput%"=="my name is %name%" goto correct @ goto :incorrect @ ...
-
空间被剪切后的字符(characters after space get cut)[2022-06-16]
是的,因为value属性的引号( " )缺失。 这与spring-mvc甚至java无关。 它与html相关 - 你应该总是引用你的属性。 Yes, because quotes (") for the value attribute are missing. This ... -
如果你输入一个带有空格的字符串, if语法会给你一个语法错误。 让我们看看: if hello world == string echo xyz if语法是: if
command 所以hello ,值1, world是比较 - 等 - 什么? world不是比较器 - 语法错误。 把你的值放在quoutes中以保证安全: if "hello world" == "string" echo xyz 所以"hello world"是value1 ... -
如何遵循脚本? 此脚本等待3秒,而“file.mp4”不存在。 它一直等到文件存在。 关于“文件名”,你可以改变你的脚本。 @echo off set waittime=3 set filename=file.mp4 :loop if not exist %filename% ( Timeout /t %waittime% /nobreak > nul goto loop ) echo Find %filename% How about following script? This script ...
-
批处理脚本:关闭空间和用户输入的某些字符(Batch Script: Closes on space and certain characters from user input)[2022-01-14]
CMD有许多具有特殊含义的字符,通常被称为“毒性字符”,因为如果它们暴露给批处理解析器,它们可能会导致许多不需要的影响。 示例包括& | > < - 还有更多。 通常,如果字符引用为">" ,或者像^>那样转义,则不会导致问题。 但是你无法控制用户输入的内容。 使用正常扩展时,某些值不安全。 例如,如果用户输入This & that "& the other thing" ,则无法在值周围添加引号,以便引用两个& 。 值得庆幸的是,延迟扩展提供了一个简单的解 而不是使用%VAR%扩展变量,而是使用!VAR! ... -
阅读help set延迟扩展。 默认情况下,当cmd解析一行时,会扩展环境变量( %foo% )。 在这种情况下,一行是一个单独的语句,可以包括一个完整的加括号的块。 因此,在解析块之后,所有出现的环境变量都将在解析时替换为其值。 如果您在块中更改了一个变量并再次使用该变量,则会看到原来的值,因为它已被替换。 延迟扩展,可以使用 setlocal enabledelayedexpansion 会导致环境变量标记为感叹号,而不是百分号( !foo! )在执行解析后的语句之前直接进行评估。 @echo off ...
-
@ECHO OFF SETLOCAL SET "sourcedir=c:\sourcedir" SET "destdir=c:\destdir" SET "textfiles=c:\bpd\*.txt" :: For my testing SET "textfiles=q20649661.txt" FOR /f "usebackqtokens=1,2delims=, " %%a IN ("%textfiles%") do ( IF EXIST "%sourcedir%\%%a*.pdf" ( ECHO ...
-
批处理脚本:验证日期输入(Batch Script: Validate Date Input)[2021-09-19]
下面的批处理文件检查插入的日期是否具有正确的格式,并且它代表有效的日期,即每个月有适当的天数,即使在闰年的2月也是如此! @echo off setlocal EnableDelayedExpansion set i=0 for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do ( set /A i+=1 set dpm[!i!]=%%a ) set /P "inDate=Please insert date (MM-DD-YYYY format ... -
使用户输入的第一个字母成为批处理脚本中的大写字母(Make the first letter of user input a capital in a batch script)[2023-09-22]
或者纯批次...... @echo off setlocal EnableDelayedExpansion call :FirstUp result hello echo !result! call :FirstUp result abc echo !result! call :FirstUp result zynx echo !result! goto :eof :FirstUp setlocal EnableDelayedExpansion set "temp=%~2" set "helper=# ... -
如何处理特殊字符(How to handle special characters)[2022-02-08]
目前还不清楚else if你的代码中else if一部分代码是你正在尝试使用的。 readline()的本质是它将返回用户输入的字符串。 输入中是否包含任何不想包含的特定字符? 您可以使用grepl()来标识它们并防止用户将它们作为输入输入。 如果您试图确保用户输入了某些内容,则应按照注释中的建议使用while循环。 如果要在函数运行后在R中使用变量,则需要return() v1的值 - 用户输入。 如果您试图用%20替换名字和姓氏之间的空格,那么您可能需要使用gsub() 。 请参阅下面的代码。 fun1 ...