Frosty840
Frosty840

Reputation: 8335

Use Find/Replace to replace arbitrary text per line?

I have a bunch of object variables which are all initialised in their declarations such that:

Private _myObject As New ThisObject("SomeString")

where ThisObject is one of a number of object types, but all are initialised using a string.

I would like to use the Visual Studio Find/Replace dialog box to search for "As New" then replace everything from "As New" to the first set of speech marks with some text such that:

EDIT

My original example could be solved using other methods. This example is more representative of the actual problem:

Private _myObjectA As New ThisObjectA("SomeString")
Private _myObjectLongName As New ThisObjectLongName("SomeString")

changes to:

Private _myObjectA = [someCode]"SomeString")
Private _myObjectLongName = [someCode]"SomeString")

Obviously this would be doable in code, reading a text file, but I'm specifically asking about the capabilities of the Visual Studio Find/Replace dialog.

OLD EXAMPLE:

Private _myObjectA As New ThisObjectA("SomeString")
Private _myObjectB As New ThisObjectB("SomeString")

changes to:

Private _myObjectA = [someCode]"SomeString")
Private _myObjectB = [someCode]"SomeString")

Upvotes: 1

Views: 176

Answers (2)

NaveenBhat
NaveenBhat

Reputation: 3318

You can do this sort of things easily using Shift + Alt + Arrow keys and Ctl + K + \ with Find/Replace dialog box. Refer my blog for more information.

Update: Follow the steps, as shown in the screen shot.

Find-Replace

Upvotes: 2

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112259

You can use regular expressions in Visual Studio. However oddly enough, VS does not use the usual .NET Regex-syntax: enter image description here

In VB you would write:

s = Regex.Replace(s, "New ThisObject\w*","[somecode]")

Upvotes: 2

Related Questions