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 = "^ ";
}
}