Previously, regular expressions were used only when I wrote message books in ASP. Code But now it is written in C. net code, and the use of ASP code is no longer practical. I have found a lot of students and many teachers have not solved the problem. There is no way to write it by myself, in fact, the reason why I don't want to write it myself is that I am not familiar with the class that calls Regular Expressions in C #. I stayed at home for a day and finally wrote it out. I also considered many actual situations, modified the previously verified functions in ASP. For example, when the image in the network is pulled, if the image is large, the webpage will be enlarged, that is, the width is greater than 1024px, so I added some JavaScript code.
The following code is useful for those who want to learn C.
Public String changechr (string CHR)
{
If (CHR = NULL)
Return ""; // match with Regexp Regular Expressions
CHR = CHR. Replace ("<", "& lt"); // Replace: Replace the matching expression with the replacement string
CHR = CHR. Replace (">", "& gt ");
CHR = CHR. Replace ("", "& nbsp ");
CHR = CHR. Replace ("\ n", "<br> ");
CHR = RegEx. Replace (CHR, @ "<script (? <X> [^ \>] *)> (? <Y> [^ \>] *) \ </script \> ", @" & lt; script $1 & gt; $2 & lt;/script & gt; ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [url = (? <X> [^ \] *) \] (? <Y> [^ \] *) \ [/url \] ", @" <a href = $1 target = _ blank> $2 </a> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [url \] (? <X> [^ \] *) \ [/url \] ", @" <a href = $1 target = _ blank> $1 </a> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [email = (? <X> [^ \] *) \] (? <Y> [^ \] *) \ [/Email \] ", @" <a href = "" mailto: $1 ""> $2 </a> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [email \] (? <X> [^ \] *) \ [/Email \] ", @" <a href = "" mailto: $1 ""> $1 </a> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [Flash] (? <X> [^ \] *) \ [/flash] ", @" <object codebase = http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid = CLSID: d27CDB6E-AE6D-11cf-96B8-444553540000 width = 500 Height = 400> <Param name = movie value = "" $1 ""> <Param name = Quality value = high> <embed src = "" $1" "Quality = high pluginspage = 'HTTP: // www.macromedia.com/shockwave/download/index.cgi? P1_prod_version = shockwaveflash 'Type = 'application/X-Shockwave-flash' width = 500 Height = 400> $1 </embed> </Object> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\", @ "
CHR = RegEx. Replace (CHR, @ "\ [color = (? <X> [^ \] *) \] (? <Y> [^ \] *) \ [/color \] ", @" <font color = $1> $2 </font> ", regexoptions. ignorecase );
CHR = RegEx. Replace (Ch *, @ "\ [** Ce = (? <X> [^ \] *) \] (? <Y> [^ \] *) \ [/face \] ", @" <font face = $1> $2 </font> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [size = 1 \] (? <X> [^ \] *) \ [/size \] ", @" <font size = 1> $1 </font> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [size = 2 \] (? <X> [^ \] *) \ [/size \] ", @" <font size = 2> $1 </font> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [size = 3 \] (? <X> [^ \] *) \ [/size \] ", @" <font size = 3> $1 </font> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [size = 4 \] (? <X> [^ \] *) \ [/size \] ", @" <font size = 4> $1 </font> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [align = (? <X> [^ \] *) \] (? <Y> [^ \] *) \ [/align \] ", @" <align = $1> $2 </align> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [Fly] (? <X> [^ \] *) \ [/Fly] ", @" <marquee width = 90% behavior = alternate scrollamount = 3> $1 </marquee> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [Move] (? <X> [^ \] *) \ [/Move] ", @" <marquee scrollamount = 3> $1 </marquee> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [glow = (? <X> [^ \] *), (? <Y> [^ \] *), (? <Z> [^ \] *) \] (? <W> [^ \] *) \ [/glow \] ", @" <Table width = $1 style = 'filter: glow (color = $2, strength = $3) '> $4 </table> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [shadow = (? <X> [^ \] *), (? <Y> [^ \] *), (? <Z> [^ \] *) \] (? <W> [^ \] *) \ [/shadow \] ", @" <Table width = $1 style = 'filter: Shadow (color = $2, strength = $3) '> $4 </table> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [B \] (? <X> [^ \] *) \ [/B \] ", @" <B> $1 </B> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [I \] (? <X> [^ \] *) \ [/I \] ", @" <I> $1 </I> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [U \] (? <X> [^ \] *) \ [/u \] ", @" <u> $1 </u> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [Code \] (? <X> [^ \] *) \ [/Code \] ", @" <PRE id = code> <font size = 1 face = 'verdana, arial 'id = code> $1 </font id = code> </PRE id = code> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [list \] (? <X> [^ \] *) \ [/list \] ", @" <ul> $1 </ul> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [list = 1 \] (? <X> [^ \] *) \ [/list \] ", @" <ol type = 1> $1 </OL id = 1> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [list = A \] (? <X> [^ \] *) \ [/list \] ", @" <ol type = A> $1 </OL id = A> ", regexoptions. ignorecase );
CHR = RegEx. Replace (CHR, @ "\ [\ * \] (? <X> [^ \] *) \ [/\ * \] ", @" <li> $1 </LI> ", regexoptions. ignorecase );
Return (CHR );
}