Replace multiple commas in a string of characters with a standard delimiter (regular expression)

Source: Internet
Author: User

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;

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.