The following C# code:
using System;
namespace TrimTest {
class Program {
static void Main(string[] args) {
Console.WriteLine(Environment.CommandLine);
Console.WriteLine(Environment.CommandLine.Trim('"'));
Console.ReadKey(false);
}
}
}
produces the following output:
"D:\Projects\TrimTest\TrimTest\bin\Debug\TrimTest.vshost.exe"
D:\Projects\TrimTest\TrimTest\bin\Debug\TrimTest.vshost.exe"
Unless I'm misreading the documentation:
The string that remains after all occurrences of the characters in the trimChars parameter are removed from the start and end of the current String object. If trimChars is null or an empty array, white-space characters are removed instead.
shouldn't the trailing double-quote be trimmed from the second string in that output?
It looks like you could be running in to a situation where there's trailing whitespace after the last double quote.
Try:
Console.WriteLine(Environment.CommandLine.Trim().Trim('"'));
And see what happens.
You could also pass extra characters in the parameter array to the overload you're already using:
Console.WriteLine(Environment.CommandLine.Trim('"', ' '));
But since I don't know what kind of whitespace there is, I prefer to use the overload that removes ALL whitespace rather than guess which character is there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With