简体   繁体   中英

How to escape whitespace using csc.exe (.NET built in C# compiler)

Like the title says, how do I escape white space passed in a file name to csc.exe? Caret's cannot be used. For example, file path C:\\Users\\user name\\My Documents\\file.cs I would normally do C:\\Users\\user^ name\\My^ Documents\\file.cs but since carets cannot be used, it throws an error. I've tried wrapping the path name in double quotes but no luck. Any help?

This is a general OS issue, not the compiler.

When you have spaces in a path, you enclose it in " :

csc <other parameters> "C:\Users\user name\My Documents\file.cs"

The caret character (^) is not recognized as an escape character or delimiter. The character is handled by the command-line parser in the operating system before it is passed to the argv array in the program.

A string enclosed in double quotation marks ("string") is interpreted as a single argument, regardless of white space that is contained within. A quoted string can be embedded in an argument. So as mentioned by Oded enclode it in ".

Reference: http://msdn.microsoft.com/en-us/library/vstudio/78f4aasd.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM