rotate matrix and replace spaces in string