Search

string TrimEnd does not return the rigth value by Jonatan Bouillon

Active

2
1
Sign in
to vote
Type: Bug
ID: 779864
Opened: 2/22/2013 11:36:37 PM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug

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

I always have in result a missing letter :
    
EtapeVerificationTransactionInteretDonneesAnnuellesGeneriqu
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

No, this is new to the most recent version
Reproduction Steps

Copy the script in PS :

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

Text :

EtapeVerificationTransactionInteretDonneesAnnuellesGenerique
File Attachments
0 attachments
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.
$FileGenerique.TrimEnd(".abdeginprsvx")

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$', ''
EtapeVerificationTransactionInteretDonneesAnnuellesGenerique
Sign in to post a workaround.
Posted by Stephen Mills on 2/23/2013 at 8:24 AM
Use "-replace" instead.

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

EtapeVerificationTransactionInteretDonneesAnnuellesGenerique