Code for conversion between HTML and UBB in C,
Code for conversion between HTML and UBB in C #
Html-to-UBB conversion is not perfect. You have time to modify it. Some code comes from Baidu Google
Private string DoHtmlToUBB (string _ Html)
{
_ Html = Regex. Replace (_ Html, "<br [^>] *>", "\ n ");
_ Html = Regex. Replace (_ Html, @ "<p [^> \/] * \/>", "\ n ");
_ Html = Regex. Replace (_ Html, "\ son [\ w] {3, 16} \ s? = \ S * ([\ '\ "]). +? \ 1 ","");
_ Html = Regex. Replace (_ Html, "
_ Html = Regex. Replace (_ Html, "<(\\/)? Blockquote ([^>] *)> "," [$1 blockquote] ");
_ Html = Regex. replace (_ Html, "] * smile = \" (\ d +) \ "[^>] *>", "'[s: $1] ");
_ Html = Regex. replace (_ Html, "] * src = [\ '\" \ s] * ([^ \ s \' \ "] +) [^>] *> ","");
_ Html = Regex. replace (_ Html, "<a [^>] * href = [\ '\" \ s] * ([^ \ s \' \ "] *) [^>] *> (. + ?) <\\/ A> "," [url = $1] $2 [/url] ");
_ Html = Regex. Replace (_ Html, "<B> (. + ?) </B> ", @" \ [B \] $1 \ [/B \] ");
_ Html = Regex. Replace (_ Html, "<[^>] *?> ","");
_ Html = Regex. Replace (_ Html, "& amp ;","&");
_ Html = Regex. Replace (_ Html, "& nbsp ;","");
_ Html = Regex. Replace (_ Html, "& lt;", "<");
_ Html = Regex. Replace (_ Html, "& gt;", "> ");
Return _ Html;
}
Public string ubbtohtml (string content) // convert ubb to html
{
Content = Regex. Replace (content, @ "\ r \ n", "<br/> ");
Content = Regex. Replace (content, "", "& nbsp ;");
Content = Regex. Replace (content, @ "\ [B \] (. + ?) \ [/B \] "," <B> $1 </B> ");
Content = Regex. Replace (content, @ "\ [I \] (. + ?) \ [/I \] "," <I> $1 </I> ");
Content = Regex. Replace (content, @ "\ [u \] (. + ?) \ [/U \] "," <u> $1 </u> ");
Content = Regex. Replace (content, @ "\ [p \] (. + ?) \ [/P \] "," <p class = 'load'> $1 </p> ");
Content = Regex. Replace (content, @ "\ [align = left \] (. + ?) \ [/Align \] "," <align = 'left'> $1 </align> ");
Content = Regex. Replace (content, @ "\ [align = center \] (. + ?) \ [/Align \] "," <align = 'center'> $1 </align> ");
Content = Regex. Replace (content, @ "\ [align = right \] (. + ?) \ [/Align \] "," <align = 'right'> $1 </align> ");
Content = Regex. Replace (content, @ "\ [url = (? <Url>. +?)] \ [/Url] "," <a href = '$ {url}' target = _ blank >$ {url} </a> ");
Content = Regex. Replace (content, @ "\ [url = (? <Url>. +?)] (? <Name>. + ?) \ [/Url] "," <a href = '$ {url}' target = _ blank >$ {name} </a> ");
Content = Regex. Replace (content, @ "\ [quote] (? <Text>. + ?) \ [/Quote] "," <div class = "quote" >$ {text} </div> ");
Content = Regex. Replace (content, @ "\ [img] (? . + ?) \ [/Img] "," ");
Return content;
}