Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:25:50+00:00 2026-06-18T04:25:50+00:00

I Created html file and I replaced some values in html file. It is

  • 0

I Created html file and I replaced some values in html file. It is fine. But I want to use for loop and replace values. But my problem is it replace only final value.

my html code :

<body bgcolor="#F5DA81">
<h1><center>Simple Report</center></h1>
<p> This report contais about comapny details according to contact details.</p>
<center><b><u><h3>Company Details</h3></u></b></center>
    <table>
        <tr><td>Company Name:</td><td><!--company--> </td></tr>
        <tr><td>Company Id  :</td><td><!--companyId--></td></tr>
    </table>
<center><b><u><h3>Contact Details</h3></u></b></center>
    <table>
        <tr><td>Contact Name:</td><td><!--contact--></td></tr>
        <tr><td>Contact Id  :</td><td><!--contactId--></td></tr>
    </table>
</body>

My for loop array to replace values.

NSMutableArray *valueArray = [[NSMutableArray alloc]init];
NSString *va = @"NU";
NSString *va1 = @"My Name";
NSString *va2 = @"WEB";
NSString *va3 = @"My Web System";

[valueArray addObject:va];
[valueArray addObject:va1];
[valueArray addObject:va2];
[valueArray addObject:va3];

NSMutableArray *myValue = [[NSMutableArray alloc]init];
NSString *val = @"<!--company-->";
NSString *val1 = @"<!--companyId-->";
NSString *val2 = @"<!--contact-->";
NSString *val3 = @"<!--contactId-->";

[myValue addObject:val];
[myValue addObject:val1];
[myValue addObject:val2];
[myValue addObject:val3];

NSMutableString *html1=[[NSMutableString alloc]init];

    for(int i = 0 ; i < 4; i++) {

        NSString *myFinalString = [myValue objectAtIndex:i];
        NSString *myVal = [valueArray objectAtIndex:i];
        html1 =[self HtmlReportName:@"myFirst" withReplaceId:myFinalString withValue:myVal];
        i = i + 1;
    }    

    [webView loadHTMLString:html1 baseURL:[[NSBundle mainBundle] resourceURL]];

Method of Html replacing.

-(NSMutableString *) HtmlReportName:(NSString *)reportName withReplaceId:(NSString *)replaceId withValue:(NSString *)value {
NSMutableString *html;
html = [NSMutableString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:reportName ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
[html replaceOccurrencesOfString:replaceId withString:value options:0 range:NSMakeRange(0, [html length])];
return html;

}

In my web view shows only last value. I want to show all replaced value in web view.

My Edited Code ::

NSMutableString *html12 = [NSMutableString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myFirst" ofType:@"html"]                                                           encoding:NSUTF8StringEncoding error:nil];

for (NSUInteger i = 0; i < [valueArray count]; i++) {

    NSString *myFinalString = [myValue objectAtIndex:i];
    NSString *myVal= [valueArray objectAtIndex:i];
    [html12 replaceOccurrencesOfString:myVal
                          withString:myFinalString
                          options:0
                          range:NSMakeRange(0, [html12 length])];
}

 [webView loadHTMLString:html12 baseURL:[[NSBundle mainBundle] resourceURL]];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:25:51+00:00Added an answer on June 18, 2026 at 4:25 am

    The issue is that you are not passing the modified HTML back into the next substitution, and you’re instead reloading the original HTML each time, and are therefore losing the previous substitution.

    Try this:

    NSMutableString *html = [NSMutableString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:reportName ofType:@"html"]
                                                             encoding:NSUTF8StringEncoding
                                                                error:nil];
    NSAssert([myValue count] == [valueArray count], @"Doh!");
    for (NSUInteger i = 0; i < [valueArray count]; i++)
    {
        NSString *myFinalString = [valueArray objectAtIndex:i];
        NSString *myVal= [myValue objectAtIndex:i];
        [html replaceOccurrencesOfString:myVal
                              withString:myFinalString
                                 options:0
                                   range:NSMakeRange(0, [html length])];
        // Remove i=i+1 !!!
    }    
    

    And dump the pointless HtmlReportName method.

    NOTE you had the use of valueArray and myValue arrays back-to-front and please give them better names!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have activated the IIS package for windows, and, I created an index.html file
I have an IntentService that is parsing some xlm file to create a html
I want to create a generic html table to excel file view that can
So I currently use the following: $.ajax({ type: GET, url: file.php, success: function(html) {
I'd like to use Javascript to make IE6 download a file. It'll be created
I've got an ajax call returning some html. The html is created and returned
I seem to have some problem with my code here. It creates a file
I want to place some helper functions in another file, since they will be
I have a file which is created by a program. It contains html code
I have created a file _emailTemplate in grails-app/views/teamplates directory.Its a html template file, The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.