AsifHabib
AsifHabib

Reputation: 950

Edit HTML file, and send HTML Email iOS

I have and HTML file which contain a thanks message, I have to append a name, designation and other detail of the user at run time at the end of file, Following is the HTML File Content

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
<TITLE></TITLE>
<META NAME="GENERATOR" CONTENT="LibreOffice 4.1.3.2 (MacOSX)">
<META NAME="CREATED" CONTENT="20140617;210025154939000">
<META NAME="CHANGED" CONTENT="20140617;210535128806000">
<STYLE TYPE="text/css">
<!--
    @page { margin: 0.79in }
    P { margin-bottom: 0.08in }
    A:link { so-language: zxx }
-->
</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<div style="color:#34495e;">Hi there,</div>
<div style="color:#34495e; margin-left:15px">Thanks Message ..... </div>
<div style="height:10px"></div>
<div>Regards,</div>
<div>QQQQ</div>
</BODY>
</HTML>

I read the file and save the content on a string, I tried to edit the content before sending email, but content is being edit. I m using following code

NSError* error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource: @"ThankEmail" ofType: @"html"];
NSString *res=[[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
[res stringByReplacingOccurrencesOfString:@"QQQQ" withString:@"MY NAME"];
NSLog(@"Message String :%@",res);

But it has no effect on String :(

Upvotes: 0

Views: 134

Answers (2)

Andrew
Andrew

Reputation: 15377

You are using an immutable string.

The stringByReplacingOccurancesOfString method returns the new string.

I believe this will do the trick:

res = [res stringByReplacingOccurrencesOfString:@"QQQQ" withString:@"MY NAME"];

Upvotes: 1

Sandy Chapman
Sandy Chapman

Reputation: 11341

Change

[res stringByReplacingOccurrencesOfString:@"QQQQ" withString:@"MY NAME"];

to

res = [res stringByReplacingOccurrencesOfString:@"QQQQ" withString:@"MY NAME"];

Upvotes: 1

Related Questions