A problem with trimstart cmdlet

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
jramon.r@tv3.cat
Posts: 18
Joined: Mon Jan 19, 2015 2:32 am

A problem with trimstart cmdlet

Post by jramon.r@tv3.cat » Thu Nov 26, 2015 4:47 am

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

User avatar
jvierra
Posts: 12380
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: A problem with trimstart cmdlet

Post by jvierra » Thu Nov 26, 2015 6:26 am

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

User avatar
jvierra
Posts: 12380
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: A problem with trimstart cmdlet

Post by jvierra » Thu Nov 26, 2015 6:31 am

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

User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Re: A problem with trimstart cmdlet

Post by dan.potter » Fri Nov 27, 2015 7:07 am

('POSPOCPA\Super3').substring(9)

Locked