Sometimes the user inputs a lot of separators, supports commas and spaces, etc. In fact, it turns out that it is just to use split to separate the separators in one place.
First of all, I know that the function of Split is to split a string into an array of strings according to the specified split character.
There is this Split in ASP, which is defined in this way. dim Split(byval source as string ,byval str as string) as string()
source is the source string, str is the delimiter
I used VB.net to explain the type of return value and parameter type.
Everyone can see how to use it.
In C#, this is how we use it
string[] Split(string source,char[] char)
Here, Char is a Char[] array. When we use it, we can set new char[]{','} in this way, so that only one splitter is defined, and we can also use new char[] {',','. ','#'} to define multiple splitters. This is a very simple usage in C#.
You can use multiple splitters to split strings in ASP. What should you do?
Split in Asp can only give a string parameter as a splitter. I have consulted some information and found no way to define multiple splitters in ASP.
It seems that I have to deal with it myself, and finally find a way: first convert all the characters in the source string that we think are to be used as splitters into a specific character, for example. Then we use this specific splitter to perform segmentation, the example is as follows:
The code copy is as follows:lcontent=Replace(lcontent,.,,)
lcontent=Replace(lcontent, ,,)
lcontent=Replace(lcontent,.,,)
lcontent=Replace(lcontent,,,) lcontent=Replace(lcontent,,,)
lcontent=Replace(lcontent, /,,)
lcontent=Replace(lcontent,/,,)
lcontent=Replace(lcontent,#,,)
lcontent=Replace(lcontent,*,,)
lcontent=Replace(lcontent,&,,)
lcontent=Replace(lcontent, :,,)
lcontent=Replace(lcontent,;,,)
rec=Split(lcontent,,)
This implements the method of using multiple splitters in Asp.
If you learn without thinking, you will not go ahead, so next I thought of the working method of Split in C#.
How can we achieve good efficiency? If it first uses char[0] to divide the string, then uses char[1] to divide it, then uses char[2], char[3]... In this way, after multiple segments, it will form an array to get the final result . It seems that this is not efficient, and I personally don’t think it will be done with this method.
So I personally think that Split in C# can also be used to implement the char[] segmentation of Split according to the above ASP? First, convert the same characters in source as Char[] into a specific splitter. Perhaps it is not ',' or maybe it is a Char that is basically impossible for us to appear in the string, so that it is more secure. Then use this specific splitter to perform the segmentation. This will be much more efficient.