rewrite the substr concatentation problem