TrimEnd

  • Can someone please explain why ccra and project (lines 1 and 3) return ccr and projec, respectively, while the other two examples return what I would expect, ccrb and projecs?

    "ccra_Data.mdf".trimend("_Data.mdf") #1

    "ccrb_Data.mdf".trimend("_Data.mdf") #2

    "Project_Data.mdf".trimend("_Data.mdf") #3

    "Projecs_Data.mdf".trimend("_Data.mdf") #4

    Thanks!

  • TrimEnd accepts a char array, not a string. This is a more explicit way to write the code:

    [char[]]$charArray = @('_','D','a','t','a','.','m','d','f')

    "ccra_Data.mdf".TrimEnd($charArray) #1

    "ccrb_Data.mdf".TrimEnd($charArray) #2

    "Project_Data.mdf".TrimEnd($charArray) #3

    "Projecs_Data.mdf".TrimEnd($charArray) #4

    Notice the letters I bolded above are contained in the char array.

    String.TrimEnd Method

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Mystery solved. Ugh.

    I managed to do what I wanted using Substring and IndexOf.

    Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply