Generate code to assign to substrings