The requirements are as follows:
Converts a string of characters to a standard separator string.
For example: ", a, svv, ss, v, v ,,,"
After conversion: "a, svv, ss, v, v"
Js implementation code:
Mostly used in the background, keyword replacement, automatic space, full-angle comma, replace with half-angle comma, and combine multiple commas<Br/> <p>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The implementation of asp.net is as follows:Copy codeThe Code is as follows: // <summary>
/// Format a group of strings such as ", a, s, d, and c" as standard separator strings such as "a, s, d, c ";
/// </Summary>
/// <Param name = "str"> character to be formatted by ref </param>
Private void strFormat (ref string str)
{
String regexText = "\\, {2 ,}";
String [] strArray = Regex. Split (str, regexText );
Str = "";
Foreach (string strf in strArray)
{
If (strf! = "")
{
Str + = strf + ",";
}
}
// If the preceding Code returns xx, xxx, x, xx, and x, remove the last comma to meet the standard delimiter conditions.
Str = str. Substring (0, str. Length-1 );
}
Regular Expressions introduce namespaces:Copy codeThe Code is as follows: using System. Text. RegularExpressions;