Recently I was trying to use backslashes in the windows cmd. And the cmds behaviour seems really strange to me. For testing out the cmds behaviour, I use this c# code here, which just outputs the passed in parameters:
namespace CsTestProject
{
using System;
static class Program
{
static void Main(string[] args)
{
foreach (string item in args)
{
Console.WriteLine(item);
}
}
}
}
If I run this program with \\\\ \\\\
as input, then the output is \\\\ \\
.
As you can see, somehow the cmd seems to be escaping the backslashes differently based on the positioning of the backslashes.
If I add a space at the end of the input and run the program again, then the output is \\\\ \\\\
.
It seems as if cmd escapes the last "backslash chain" if there is no other character after the last "backslash chain". It looks something like this when I express it in code:
if (no character after last backslash chain)
{
escape last backslash chain
}
else
{
do nothing
}
Can someone explain to me what is going on?
Thank you very much for your help!