$path = "\path\to\my\file"
I want to simply remove the first \
how do I do that?
I don't want to remove the first character if it's a letter, only if it's \
$path = "\path\to\my\file"
I want to simply remove the first \
how do I do that?
I don't want to remove the first character if it's a letter, only if it's \
$path = $path.TrimStart("\")
Would convert $path
to path\to\my\file
Take note that subsequent leading backlashes would also be removed as well, so if you had \\\path
it would be reduced to path
!
You could use the regex -replace
operator:
$path = $path -replace '^\\'
This will remove exactly 1 backslash from the start of the string