VS regular expression replacement content, vs regular expression replacement

Source: Internet
Author: User

VS regular expression replacement content, vs regular expression replacement

Rarely use the regular expression replacement function of VS. Recently, because a large number of default values need to be added, but you don't want to re-class, you just thought of this.

1. Replace attributes with // descriptions

The regular expression to be searched:

/// <Summary> ((.) *((. | \ n) {1, 2}) {1, 2 }///(. {1 ,})((.) *((. | \ n) {1, 2}) {1, 2} // </summary> ((.) *((. | \ n) {1, 2}) {1, 2} public string (. {1 ,}) {get; set ;}

Replace the regular expression:

Private string _ $14; \ n // <summary> \ n // $5 \ n /// </summary> \ n public string $14 {\ nget \ n {\ nif (string. isNullOrWhiteSpace (_ $14) \ n {\ n _ $14 = ""; \ n} \ nreturn _ $14; \ n} \ nset \ n {\ n _ $14 = value; \ n}

$1... $ n indicates the matching items. Most of the time it is calculated by yourself, it may be incorrect. In this way, where to replace it: $1; $2 ;....; $ n in this way, you can intuitively know that it is the value you want. In the above replace expression, $5 is the comment content, and $14 is the attribute name;

2. Replace uncommented attributes

The regular expression to be searched:

Public string (. {1,}) {get; set ;}

Replace the regular expression:

\ Nprivate string _ $1; \ n // <summary> \ n // $1 \ n // </summary> \ n public string $1 {\ nget \ n {\ nif (string. isNullOrWhiteSpace (_ $1) \ n {\ n _ $1 = ""; \ n} \ nreturn _ $1; \ n} \ nset \ n {\ n _ $1 = value; \ n}

Here is a simple usage.

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.