c# - What's the proper way to deal with \ in .NET console application arguments? -


this question has answer here:

i wrote small application copy files source destination. expected 2 parameters, source , destination. following command works fine.

test.exe "c:\source path" "d:\destination" 

the problem have when pass parameter within " , end \ messes up.

for example:

test.exe "c:\source path\" "d:\destination" 

since \ escape character test.exe gets first argument c:\source path" instead of c:\source path\

so, what's proper way deal problem.

even basic sample shows strange behavior - \" passed command line converted ":

static void main(string[] args) {  foreach(var s in args)  {     system.console.writeline(s);  } } 

 test.exe @"c:\source path\" @"d:\destination" 

the @ makes string verbatim literal.

in verbatim string literal, characters between delimiters interpreted verbatim, exception being quote-escape-sequence.

read more here on msdn


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -