Implemented character swapping to prevent invalid characters appearing in formatting.