Q:

Text files with ampersands drawn into email message stop template

Admittedly, I'm a rookie. With that said I cannot fully understand an issue and I'm hoping you all can help me isolate the resources I need to investigate. Let me explain the flow and then I'll describe the problem.
I have a program that follows this cycle:
1) The program retrieves text from txt files on my system and stores the content inside NSStrings.
2) The program compiles a report and uses the info from each NSString to populate different sections of an email template.
PROBLEM: When a text file contains ampersands, the email does not populate the template any further than the line before the ampersand.
I cannot control the contents of these files and some contain ampersands, either in text or links within the file.
For example if the body of an email should read as described below, I will never see the last half of the email.
SECTION ONE:

This text came from one file

SECTION TWO:

This text & that text from another file

SECTION THREE:

Additional information from another file

If I NSLog the contents of the second section's message, I do see the full content, including the ampersand, but it does not appear when the data is drawn into the mail app through [[NSWorkspace sharedWorkspace] openURL:mailtoURL];
The other part that confuses me is that when I create an NSString within the app that doesn't draw from an external source, ampersands DO move into the mail message successfully.
What do I need to look into to make this play nice?

A:

You might want to replace any occurrence of & with &amp; if your template is rendered as HTML.
text = [text stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"]

A:

The only way I could get it to work is just a substitution...
body = [body stringByReplacingOccurrencesOfString:@" & " withString:@" and "];
body = [body stringByReplacingOccurrencesOfString:@"&" withString:@" "];

That way the word "and" is always written out and links containing "&" break, but are still usable in the emails.
It's not elegant, but it works. I still welcome any insights as to what may be happening within the app or mail app that dislikes ampersands being imported.

