This seems like such a simple requirement, that I feel like I am missing something obvious.
I have an Excel spreadsheet with “dirty” text data in, containing text and unwanted leading and trailing, spaces, commas and newlines. I would like to TRIM references to these cells of all those characters.
Note: I don’t want to replace all those characters, since they legitimately appear within the cell text – it is just when at the start or end of the cell text (i.e. value) that I want to trim them off.
The text data consists of names of people and schools, for cleaning and importing into a CRM.
So, is there a function built in, or do I need to write one? I feel spoiled by the number of string filtering functions in PHP 😉
This is well suited to a regexp
The code below adapted from this article uses this regexp
"[,\s]*(.+?)[,\s]*$"to remove any leading and/or trailing whitespaces/commas while leaving any such characters within the text body intact
It will replace your existing data in-situ