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 7509717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:00:03+00:00 2026-05-29T23:00:03+00:00

I have an HTML file that will act as a template for an email

  • 0

I have an HTML file that will act as a template for an email that I am going to send out. There are fields in the html that are variable. I was wondering if there is a robust way to replace the placeholders in the HTML file with the variables. I know I could string.Replace all of them, but that isn’t ideal since I have a lot of variables. Here is what the html file looks like

<html>
<head>
<title></title>
</head>
<body>
<div>
    Please read the Cruise Control Details Below<br>
    <br>
    <table width='100%'>
        <tr>
            <td width='100%' colspan='5'>
                <font size='4'><b>Release Details</b></font>
            </td>
        </tr>
        <tr>
            <td width='20%'>
                <b>RFC Ticket #</b>
            </td>
            <td>
                %release.RFCTicket%
            </td>
            <td>
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
            <td width='10%'>
                &nbsp;
            </td>
            <td width='20%'>
                <b>Project / Release Name</b>
            </td>
            <td width='20%'>
                %release.ReleaseName%
            </td>
        </tr>
        <tr>
            <td width='20%'>
                <b>Release Date</b>
            </td>
            <td width='20%'>
                %release.ReleaseDateString%
            </td>
            <td>
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
            <td width='10%'>
                &nbsp;
            </td>
            <td width='20%'>
                <b>Release Time</b>
            </td>
            <td width='20%'>
                %release.ReleaseTimeString%
            </td>
        </tr>
        <tr>
            <td width='20%'>
                <b>CAB Approval Status</b>
            </td>
            <td width='20%'>
                %release.CABApproval%
            </td>
        </tr>
        <tr>
            <td width='100%' colspan='5'>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td width='100%' colspan='5'>
                <font size='4'><b>Contact Information:</b></font>
            </td>
        </tr>
        <tr>
            <td width='20%'>
                <b>Project / Team Lead</b>
            </td>
            <td width='20%'>
                %release.TeamLead%
            </td>
            <td width='10%'>
                &nbsp;
            </td>
            <td width='20%'>
                <b>On Call DSE</b>
            </td>
            <td width='20%'>
                %release.OnCallDSE%
            </td>
        </tr>
        <tr>
            <td width='20%'>
                <b>Phone</b>
            </td>
            <td width='20%'>
                %release.ContactInfo%
            </td>
            <td>
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
            <td width='10%'>
                &nbsp;
            </td>
            <td width='20%'>
                <b>Phone</b>
            </td>
            <td width='20%'>
                %release.OnCallDSEContact%
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td width='100%' colspan='5'>
                <font size='4'><b>Migration Details:</b></font>
            </td>
        </tr>
        <tr>
            <td width='20%'>
                <b>Deploy Dashboard</b>
            </td>
            <td width='20%'>
                &nbsp;
            </td>
            <td width='10%'>
                &nbsp;
            </td>
            <td width='20%'>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <b>Deploy Task</b>
            </td>
            <td width='20%'>
                &nbsp;
            </td>
        </tr>
        %createTaskTable(ParseSpecialInstuctions().Split('|'))%</table>
</div>

I would like to replace the values in between the “%%” with the variable in code that represents them. I could easily

string.Replace("%release.RFCTicket%",release.RFCTicket);

But that’s a bit convoluted in my opinion since I have like 10 or so variables in the file. Are there any built in methods that do what I am asking? Any help would be appreciated, thanks!

  • 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-05-29T23:00:05+00:00Added an answer on May 29, 2026 at 11:00 pm

    Use a regular expression to find your matches. I believe the appropriate regular expression would be along the lines of:

    %release.\S+%
    

    From there, you can examine each match, and parse the member name from the match. From there you can get the value of the member from your instance (release in this case) via reflection, and do a string replace.

    Something like this. It could use some refactoring to eliminate redundant calls, and I don’t know if it fully works, but you get the idea…

    var regex = new Regex("%release.\S+%");
    var match = r.Match(htmlText);
    while (match.Success) 
    {   
        var value = match.Value;
        var memberName = ParseMemberName(value); //Some code you write to parse out the member name from the match value
        var propertyInfo = release.GetType().GetProperty(memberName);
        var memberValue = propertyInfo.GetValue(release, null);
        htmlText = htmlText.Replace(value, memberValue != null ? memberValue.ToString() : string.Empty);
        match = match.NextMatch();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have he following scenario: Got an HTML template file that will be used
I have long recognized that any set of whitespace in an HTML file will
Absolute beginner question: I have a template file index.html that looks like this: ...
I have simple template that's html mostly and then pulls some stuff out of
I have a Python script that will look at an HTML file that has
I have three simple html or php file that I'm going to create. What
I have a form in a HTML file that will post values from the
I have a HTML file that has code similar to the following. <table> <tr>
I have a html file that has invoice details I would like to know
I have a html file that contains urls that start with ftps, http, https,

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.