Refactor string functions, fix many defects.

Not for lines like these I'm afraid. Parens should be used in one of two cases:
i) to force operator precedence
ii) to avoid assign-as-truth-value warnings.

Neither apply in this case and parens just adds line noise.