Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Find and Replace Variables

I am trying to replace a two letter state abbreviation with text then the abbreviation. Eventually I want to find and replace the rest. How do I capture the value found? .... I tried \1 and {1}

AL  32.2679134368897    -86.5251510620117
AR  35.2315113544464    -92.2926173210144
AZ  33.3440766538127    -111.955985217148
CO  39.7098631425337    -104.899092934348

if( usState == "AZ") dpos= "33.4736704187888" + " " + "-112.043138087587";
if( usState == "CA") dpos= "36.0783581515733" + " " + " -119.868895584259";
if( usState == "CO") dpos= "39.8950788035537" + " " + " -104.831521872318";
if( usState == "CT") dpos= "41.6001570945562" + " " + " -72.6606015937273";

Update $1 does not work.

I am finding: [A-Z][A-Z] replacing with: if( usState == "$1

like image 881
Bryan Avatar asked May 01 '09 01:05

Bryan


People also ask

How do I find and replace in Visual Studio?

You can find and replace text in the Visual Studio editor by using Find and Replace (Ctrl+F or Ctrl+H) or Find/Replace in Files (Ctrl+Shift+F or Ctrl+Shift+H). You can also find and replace only some instances of a pattern by using multi-caret selection.

How do you replace a value in VS code?

You can use the Find control in code or text windows, such as Output windows and Find Results windows, by selecting Edit > Find and Replace or pressing Ctrl+F.


2 Answers

Oddly enough, Visual Studio Regular Expressions are different than normal .Net regular expressions. They have a slightly different syntax for tags and replaces. In order to tag a piece of text for later matching you must wrap it in braces {}. Then you can use \n in the replacement strings where n is the nth tagged expression. For your scenario here are the strings you should use

  • Find: {[A-Z][A-Z]}
  • Replace: if( usState == "\1")
like image 126
JaredPar Avatar answered Oct 18 '22 03:10

JaredPar


My regex matcher matches $1. Try that.

like image 4
Stefan Kendall Avatar answered Oct 18 '22 03:10

Stefan Kendall