You can use Javascript to trim strings.
storeEval | a = storedVars['q']; a = a.replace(/( |\n|\r)/gm, ""); a | trimmedQ
You find this line in the DemoPDFTest_with_OCR macro.
Related: See here for extracting substrings: