$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 may want to mention that the
.Trim()
variants trim the characters as individual chars in the parens ... and trim ALL OF THEM. so, your code would trim away all the leading backslash characters. that is fine when you expect it ... but truly disconcerting when it happens unexpectedly. [grin]