function to reverse string in place