Refactor string functions, fix many defects.

Shouldn't this be Format.h?