C # UBB Code Conversion

Source: Internet
Author: User

Although there are many online editors on the internet, I generally don't use that function. after thinking for a long time, I decided to write a simple online editor and support several simple text processing methods. So I wrote one long ago, however, in UBB conversion, this part is used by others.CodeI forgot who wrote it, but other people's code will use a lot of problems, for example, [B] [B] AAA [/B] [/B] cannot be implemented well, the result is <B> [B] AAA </B> [/B], which is a headache for me and has to be reminded, never [B] [B] AAA [/B] [/B. But now it is much better. after a long time of research, it turns out that others are trying to increase the speed. Let's take a look at the two differences.

Others: R is a RegEx object, and M is a match object. For (M = R. match (); M. success; M = m. nextmatch ()){......} the problem lies in M = m. nextmatch (), which searches for the next match after the last match. To avoid this, I changed it,

// Process [B] [/B]
R = new RegEx (@ "/[B] ([/S] *?) /[/B] ");
M = R. Match (STR );
While (M. Success)
{
STR = Str. Replace (M. Groups [0]. tostring (), "<B>" + M. Groups [1] + "</B> ");
M = R. Match (STR );
}

In this way, the problem [B] [B] AAA [/B] [/B] can be solved, but the efficiency may be slightly different, but when the traffic is small, no. Haha ......

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.