trim string value before transform it in a primitive

I think you should do this after the test for Character/char, else you'll never be able to coerce to char ' '.