Support Forums

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.
User avatar
jramon.r@tv3.cat
Posts: 15
Joined: Mon Jan 19, 2015 2:32 am

A problem with trimstart cmdlet

Postby 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: 10032
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: A problem with trimstart cmdlet

Postby 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: 10032
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: A problem with trimstart cmdlet

Postby 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/library/system.string.trimstart(v=vs.110).aspx
User avatar
dan.potter
Posts: 661
Joined: Wed Oct 08, 2014 6:02 am

Re: A problem with trimstart cmdlet

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

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

Return to “Windows PowerShell”

Who is online

Users browsing this forum: No registered users and 2 guests