Refactor string functions, fix many defects.

Use ToHex.