Delete blank lines in multi-line text boxes
In some research or voting procedures, there are two options to set the topic, and there are two most common ways:
1. Each time you add a selection branch, if the title has n option, add N times;
2. Fill all the options into a text box, divide each option with a special separator (eg, "," $ ", and then processes the resulting content.
If there is only a small number of topics in the investigation or voting program, it is still more complicated in the topic. Therefore, there are many cases in many cases.
In the second approach, it is more convenient and intuitive, and it is more useful to fill in all the options in the multi-line text box, each option occupies a row, and then generates a selection item at once according to the content filled in. But this method is accompanied by a problem: how to eliminate the blank line generated by accidental error input.
The possible blank line mainly has a purely blank row generated by a carriageway and two blank lines generated by one or more spaces (it is also possible to mix by tabs or tabs and blank lines, but this Something is very similar, the method is also similar). There are three places where the blank line is generated: the segment, the paragraph and the end. And each blank may be composed of one or more lines.
The general processing method is to divide each option, using array storage, traversing an array, if an item of an array is empty, then delete the item, then generate a selection item. I have encountered this situation, I think it is more troublesome with array processing, compared with the regular expression, it is relatively simple.
The function is as follows:
Imports System.Text.RegularExpressions
Function DealwithBlank (Byval Str As String) AS String
'Treatment front and back and middle space blank line
Str = regex.replace (STR, "^ * / r / n", "", regexoptions.multiline)
Str = Regex.Replace (STR, "/ R / N * $", VBCRLF, RegexOptions.Multiline
'Treating a carriage return to the car
Str = regex.replace (STR, "(/ R / N) {1,}", VBCRLF)
Str = regex.replace (STR, "/ r / n $", "")
'Returns a string that meets the text box format
Return Str
END FUNCTION
example:
INDEX.ASPX
<% @ Page language = "vb" autoeventwireup = "false" codebehind = "index.aspx.vb" inherits = "test.webform1"%>
3C
// DTD HTML 4.0 Transitional // En ">
HEAD>