It sounds like you want an ordered set, ordered by the first occurrence of the item within the first string, or (for items not present in the first string) the first occurrence of the item within the second string.
Easiest thing to do is to have a set, and an string. Iterate over the first string; for each item, if it's not in the set, add it to the set and append it to the string. Then do the same for the second string.