Event-driven automatic generation of Static Page Templates solution (3) -- text content replacement

Source: Internet
Author: User
Tags element groups

Simple class encapsulation of text replaced by template content

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace xingmai. informationprovider. Factory
{
Public class stringbuilder
{
Private respacearraylist _ replacelist = new respacearraylist ();
Private textcommonreplacelist _ commonreplacelist = new textcommonreplacelist ();
Private string _ template;

/// <Summary>
/// Template
/// </Summary>
Public String Template
{
Get
{
Return _ template;
}
Set
{
_ Template = value;
}
}

/// <Summary>
/// Replace element groups
/// </Summary>
Public respacearraylist replacelist
{
Get
{
Return _ replacelist;
}
Set
{
_ Replacelist = value;
}
}

/// <Summary>
/// General replacement group
/// </Summary>
Public textcommonreplacelist commonreplacelist
{
Get
{
Return _ commonreplacelist;
}
}

Public stringbuilder ()
{
}

///


// initialize and set the template
///
///
Public stringbuilder (string strtemplate)
{< br> template = strtemplate;
}

///


// generate a text
///
///
Public String writetext ()
{< br> return writetext (true);
}

Public String writetext (bool iscommand)
{< br> string strcontent = template;
foreach (replaceitem RI in replacelist. array)
{< br> strcontent = strcontent. replace (string. format ("{0} {1} {0}", replaceconfig. replacetag, Ri. label), Ri. text);
}

If (iscommand)
Foreach (replaceitem RI in commonreplacelist. array)
{
Strcontent = strcontent. Replace (string. Format ("{0} {1} {0}", replaceconfig. replacetag, Ri. Label), Ri. Text );
}

Return strcontent;

}
}

///


// General replacement group
///
public class textcommonreplacelist: respacearraylist
{< br> Public textcommonreplacelist ()
: Base ()
{< br> base. add ("D", datetime. now. day. tostring ();
base. add ("M", datetime. now. day. tostring ();
base. add ("Y", datetime. now. year. tostring ();

Base. Add ("H", datetime. Now. Hour. tostring ());
Base. Add ("F", datetime. Now. Minute. tostring ());
Base. Add ("S", datetime. Now. Second. tostring ());
}
}

/// <Summary>
/// Replace element groups
/// </Summary>
Public class respacearraylist
{
Private list <replaceitem >_list = new list <replaceitem> ();

///


// Add a replacement element
///
///
//
Public void add (replaceitem item)
{< br> _ list. add (item);
}

///


// Add a replacement element
///
/// replace element tags
/// replace element content
///
Public void add (string strlabel, string strtext)
{< br> _ list. add (New replaceitem (strlabel, strtext);
}

///


// remove the replacement element group
///
///
Public void remove (replaceitem item)
{< br> _ list. remove (item);
}

/// <Summary>
/// Delete the replacement element of the specified Element
/// </Summary>
/// <Param name = "Index"> </param>
Public void removeat (INT index)
{
_ List. removeat (INDEX );
}

/// <Summary>
/// Replace the element index
/// </Summary>
/// <Param name = "I"> </param>
/// <Returns> </returns>
Public replaceitem this [int I]
{
Get
{
Return _ list [I];
}
Set
{
_ List [I] = value;
}
}

///


// return the array of replacement elements
///
Public replaceitem [] array
{
Get
{< br> return _ list. toarray ();
}< BR >}< br>
}

/// <Summary>
/// Replace Element
/// </Summary>
Public class replaceitem
{
Private string _ label;
Private string _ text;

Public replaceitem ()
{
}

/// <Summary>
/// Replace Element Definition
/// </Summary>
/// <Param name = "strlabel"> replace an element label </param>
/// <Param name = "strtext"> replace element content </param>
Public replaceitem (string strlabel, string strtext)
{
Label = strlabel;
TEXT = strtext;
}

/// <Summary>
/// The tag to be replaced
/// </Summary>
Public String label
{
Get
{
Return _ label;
}
Set
{
_ Label = value;
}
}

/// <Summary>
/// Replaced with content
/// </Summary>
Public String text
{
Get
{
Return _ text;
}
Set
{
_ Text = value;
}
}
}

/// <Summary>
/// Replace the configuration
/// </Summary>
Public class replaceconfig
{
/// <Summary>
/// Tag ID
/// </Summary>
Public const string replacetag = "^ ";
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.