ASP.NET (35) SQL (25) JAVASCRIPT (24) HTML (14) STYLE SHEET (6) ASP (4) SCRIPT (1)

Search me out HERE!!

Find and Replace in Visual Studio using regular expression

One of the nice feature in all version of visual studio that I would love to use is Find and Replace using regular expression. This feature is very useful while you need to perform any repeating pattern based task. and offcourse it saves a lot time.
Lets take a simple example to understand it. We have list of countries and its code in a excel file or table. We want to create a dropdownlist from it so text field contains Country name and Value field contains Code in it.

The step by step procedure:


Step 1: Select the both columns from excel file an copy it in text file in visual studio. Don’t forget to put cursor at the start.


Step 2: Now click Ctrl+h to open the find replace dialog.  Checkmark the last checkbox 'Use' and select ‘Regular Expression’ from the dropdown. Now we will need to define the regular expression in ‘Find What:’ and ‘Replace with:’ textboxes. You can see them in following screenshot (again i will explain how to define it? and how does it work? in my next post)



Step 3: Click on ‘Replace All’ button on the dialog. and Here is the result we need.

This feature reduces your manual work.

2 comments:

  1. Can you please describe above used regular expression if possible..

    Thanks..

    ReplyDelete
    Replies
    1. {[^\t]*} takes first word and it is considered as "1"
      \t consider the space
      {[^\n]*} takes all other letters and it is considered as "2"

      "1" and "2" are replaced in "replace with" text

      Delete