City of Toronto interview question

how to string trim safely?