Page 1 of 1

A problem with trimstart cmdlet

Posted: Thu Nov 26, 2015 3:47 am
by jramon.r@tv3.cat
I have an script with the cmdlet trimstart and I've checked that when the string that I want starts with "S" it trims the "S" too. F.ex. i have

$user='POSPOCPA\Super3'
$user=$user.TrimStart("POSPOCPA\")

The result is $user=uper3

but if I have

$user='POSPOCPA\super3'
$user=$user.trimstart("POSPOCPA\")

then the result is ok $user=Super3

is there any explication for this?

Thanks

Re: A problem with trimstart cmdlet

Posted: Thu Nov 26, 2015 5:26 am
by jvierra
This is a little used feature of Windows PowerShell.
This is the current way to enable the feature.

PS C:\scripts> $user='POSPOCPA\Super3'
PS C:\scripts> $user.TrimStart("POsPOCPA\")
SPOCPA\Super3

Re: A problem with trimstart cmdlet

Posted: Thu Nov 26, 2015 5:31 am
by jvierra
If you read the documentation for the "TrimStart" method he answer will become very clear. The issue si the "TrimStart" does not do what you think it does:

https://msdn.microsoft.com/en-us/librar ... .110).aspx

Re: A problem with trimstart cmdlet

Posted: Fri Nov 27, 2015 6:07 am
by dan.potter
('POSPOCPA\Super3').substring(9)