Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / February 2006

Tip: Looking for answers? Try searching our database.

Regular Expression Find and Replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Bysouth - 16 Feb 2006 00:55 GMT
Hi

In some of the code I'm working with (porting very very old code with bits
going back to VB1 days!), we've got comments that are un uppercase. I want to
be able to change these to lowercase without going through them manually.

Is there a way to do this using the RegEx bit of the Find and Replace
dialog? If so, can you provide an example of the RegEx needed for the Find
and Replace fields please?

Or would this have to be done using a Macro?

e.g. 'THIS IS MY COMMENT

should become

'this is my comment

ok, it's just an aesthetic thing but ucase looks out of place!

thanks

Richard
"Gary Chang[MSFT]" - 16 Feb 2006 07:55 GMT
Hi Richard,

>Is there a way to do this using the RegEx bit of the Find
>and Replace dialog?

You can use the following RegEx to match all the comment  in the Visual
Studio's Find what field:
'.+$

but I am afraid the Replace filed does not support RegEx, so you could not
use the RegEx to replace those commnets in Visual Studio.

>Or would this have to be done using a Macro?

yes, based on my test, the following Macro code could change all the
characters of the current active document's comments text  to lowercase:

Public Sub FindAndReplace()
   Dim objTextDoc As TextDocument
   Dim objEditPt As EditPoint, iCtr As Integer

  objTextDoc = DTE.ActiveDocument.Object("TextDocument")
   objEditPt = objTextDoc.StartPoint.CreateEditPoint

   While (objEditPt.FindPattern("'.+$",
vsFindOptions.vsFindOptionsRegularExpression) = True And
objEditPt.AtEndOfDocument <> True)
       objEditPt.ChangeCase((objEditPt.LineLength -
objEditPt.LineCharOffset) + 1, vsCaseOptions.vsCaseOptionsLowercase)
       objEditPt.LineDown()
   End While

End Sub

Whish this helps!

Best regards,

Gary Chang
Microsoft Community Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006.  Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
Richard Bysouth - 16 Feb 2006 08:23 GMT
Gary

thanks for the quick response - yes that works fine for me.

I think i'll modify it to loop through the entire project at some point.

Haven't really used VS macros before but think I will have to now - very
useful!

Richard
"Gary Chang[MSFT]" - 16 Feb 2006 09:06 GMT
Hi Richard,

I am glad to know it helps, good luck.:)

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006.  Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.