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 ......