string TrimEnd does not return the rigth value - by Jonatan Bouillon

Status : 


Sign in
to vote
ID 779864 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 2/22/2013 11:36:37 PM
Access Restriction Public


  $FileGenerique = "EtapeVerificationTransactionInteretDonneesAnnuellesGenerique.aspx.designer.vb"
    $LeftPartFileNameGenerique = $FileGenerique.TrimEnd(".aspx.designer.vb")

I always have in result a missing letter : 
Sign in to post a comment.
Posted by Stephen Mills on 2/23/2013 at 8:23 AM
I think you misunderstand what TrimEnd does. It removes all instance of any of the characters you give it from the end of the string. The parameter for TrimEnd is actually a char array, not a string.

The following will give you the same results as your example.

I'm sure there are many ways to get what you are looking for in powershell, but I personally like using "-replace". It does use regex, so it's a little bit harder to get started with, but in this case you would need to escape the periods "\." and end the string with "$" to tell it to only look at the end of the line.

$FileGenerique -replace '\.aspx\.designer\.vb$', ''