none
Where is the charter "i"? trim() removing the character 'i' from the string RRS feed

  • Question

  • I am Writing some script to trim the word "profile" and the spaces, to my surprise its also trim the letter "i" below is the sample from powershell. Please let me know if i am missing something.

    PS C:\workdbps> $t="profile profile\tcp_sockets_test1.ini"

    PS C:\workdbps> $t.Trim("profile").trim()

    profile\tcp_sockets_test1.in

    #another way to reproduce it

    PS C:\workdbps> $t="profile profile\tcp_sockets_test1.ini"

    PS C:\workdbps> $t.Trim("profile")
     profile\tcp_sockets_test1.in


    Excepted Output:- profile\tcp_sockets_test1.ini

    Actual Output:-      profile\tcp_sockets_test1.in     ===> Where is "i" why it trim out?

    It work fine for below scenarrio

    PS C:\workdbps> $t="profile profile\tcp_sockets_test1.ini123"

    PS C:\workdbps> $t.Trim("profile").trim()

    profile\tcp_sockets_test1.ini123



    Saturday, October 12, 2013 5:15 AM

All replies

  • Its because of "profile" in the trim function. if i modify the trim function with trimStart(), it resolved the problem. Still i think its wearied design it should consider that as a one trim string and should not be consider it character by character.

    PS C:\workdbps> $t="profile profile\tcp_sockets_test1.ini"

    PS C:\workdbps> $t.TrimStart('profile') 

    profile\tcp_sockets_test1.ini


    Saturday, October 12, 2013 5:24 AM