TrimStart() removes characters from the start of a string, so when you pass 
'0-24.', you're actually telling it to remove the characters '0', '-', '2', 
'4', and '.' from the start of the string.  '5' is the first character that 
doesn't match, so that's where the new string starts.  See the MSDN article for 
more details: 
https://msdn.microsoft.com/en-us/library/system.string.trimstart.aspx

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On 
Behalf Of Mote, Todd
Sent: Tuesday, October 4, 2016 1:22 PM
To: scripting@lists.myitforum.com
Subject: [scripting] powershell trimstart?

Stumbled across this in the last couple of days, can anybody tell me what's 
going on?

I have a string:  '0-24.254.16.172.in-addr.arpa'

I need to remove the '0-24.' From the front so I thought, trimstart would get 
me what I needed, however

('0-24.254.16.172.in-addr.arpa').trimstart('0-24.') returns

54.16.172.in-addr.arpa

If I take out the dot and run 
('0-24.254.16.172.in-addr.arpa').trimstart('0-24') it returns

.254.16.172.in-addr.arpa

I know I could use substring to get the results I need, or even 2 trimstarts, 
('0-24.254.16.172.in-addr.arpa').trimstart('0-24').trimstart('.')
, but why does it trim the '2' when I have the dot in there and trims what it's 
told when it's not?  what's special about a dot inside a string?  I've seen the 
same behavior with front slash "/".  Double vs single quotes doesn't seem to 
matter.  I also thought maybe it needs to be escaped, but putting a backtick in 
doesn't change the outcome either.  Any ideas?

Todd




Reply via email to