Protected string trimhtml (string input, int length)
{
String inputhtml = input. Trim ();
Stringbuilder outhtml = new stringbuilder ();
Int maxlength = length;
If (maxlength <inputhtml. length)
{
Inputhtml = inputhtml. substring (0,505 );
String firstmatch = "";
String lastmatch = "";
Bool isregexmatch = false;
String patternmatchhtml = @ "(<([a-z0-9] *) ([^>] *)> (. *) </S */2>) | (<([a-z0-9] *) ([^>] *)/S *> )";
RegEx = new RegEx (patternmatchhtml, regexoptions. ignorecase );
Match m = RegEx. Match (inputhtml );
While (M. Success)
{
Isregexmatch = true;
If (firstmatch = "")
Firstmatch = M. value;
Lastmatch = M. value;
Outhtml. append (M. value );
M = M. nextmatch ();
}
If (isregexmatch)
{
String beforestring = "";
If (firstmatch! = "")
{
Beforestring = inputhtml. substring (0, inputhtml. indexof (firstmatch ));
}
Bool hasmeetingtag = false;
For (INT I = beforestring. Length-1; I> = 0; I --)
{
If (beforestring [I] = '> ')
{
Hasmeetingtag = true;
}
Else if (beforestring [I] = '<')
{
Hasmeetingtag = false;
}
Else
{
If (! Hasmeetingtag)
Outhtml. insert (0, beforestring [I]);
}
}
String laststring = "";
If (lastmatch! = "")
{
Laststring = inputhtml. substring (inputhtml. lastindexof (lastmatch) + lastmatch. Length );
}
Hasmeetingtag = false;
For (INT I = 0; I <laststring. length; I ++)
{
If (laststring [I] = '<')
{
Hasmeetingtag = true;
}
Else if (laststring [I] = '> ')
{
Hasmeetingtag = false;
}
Else
{
If (! Hasmeetingtag)
{
Outhtml. append (laststring [I]);
}
Else
Outhtml. append (inputhtml );
}
Return outhtml. tostring (). Trim ();
}
}
}
}