Using quick search results in a single whitespace character being added to beginning and end of a string

Hello. I have a grid application where if a user clicks on a record’s value that value is saved in a global variable so that it can be used when navigating to the next application. This works fine unless the user uses any of the search methods (Quick search, dynamic search etc.). For some reason when they search for a string a single whitespace character is added to the front and end of a string.

I’ve tried trimming whitespace from the string using the PHP trim() function. However, the whitespace still remains even when I do that. Does anyone happen to know what the cause of this is and how I could possibly prevent it from happening?