Correct use of TrimEnd This topic contains 2 replies, has 2 voices, and was last updated by Scott Halepaska 1 year ago. Author Posts June 12, 2017 at 3:39 pm #72649 Scott HalepaskaParticipant I am having a hard time removing a string element with TrimEnd. I am trying to remove the '.jrnl' from the strings human.jrnl and humans.jrnl using the following $journal = "humans.jrnl" $journal.ToLower().TrimEnd(".jrnl") This works fine with humans but human returns the string 'huma'. What is the correct way to accomplish this? June 12, 2017 at 4:05 pm #72653 Don JonesKeymaster TrimEnd() technically takes an array of single characters, not a string. See https://msdn.microsoft.com/en-us/library/system.string.trimend(v=vs.110).aspx. PowerShell is likely turning ".jrnl" into an array, which means it will remove ., j, r, n, and l from the end. TrimEnd() is a bit more powerful than you might realize. But for what you're doing, it'd be much easier just to do a... $journal = $journal -replace ".jrnl","" June 12, 2017 at 4:15 pm #72658 Scott HalepaskaParticipant Thanks for the reply. I will use the replace function. I find it interesting that TrimEnd is consuming only specific extra characters. I have noticed the behavior with 'n' and 'r' so maybe it is treating them as ascii codes. Author Posts You must be logged in to reply to this topic.