Warm tip: This article is reproduced from stackoverflow.com, please click
powershell

remove first character if a specific character

发布于 2020-03-27 10:15:18
 $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 \

Questioner
whoisearth
Viewed
104
gravity 2019-07-03 21:04
$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!