Question:
How to use regular expressions? Visual Studio?
karljj1
2009-07-21 13:23:35 UTC
Hi.

I have some comment blocks formatted like so:

//************************************
// Method: ....
// FullName: ....
//!Description: Do something
// Some more description
// Some more
// Access: virtual public
// Returns: void
// Qualifier:
// Parameter:
//************************************

I need to change the // that is part of the descriptor into a //!

E.G


//************************************
// Method: ....
// FullName: ....
//!Description: Do something
//! Some more description
//! Some more
// Access: virtual public
// Returns: void
// Qualifier:
// Parameter:
//************************************


The comment block descriptions are various lines long and i have thousands of comments to change so doing it manually is not an option.

Can someone show me a regular expression or wildcard that i could use in visual studio to automate this, i have been reading up on regex but cant really understand them. Thanks.
Three answers:
Paul
2009-07-21 14:06:31 UTC
I think you need to do this in 3 steps:



(1) change all the known lines to something special, temporarily, e.g.



//***********************************…

//

//+Method: ....

//+FullName: ....

//!Description: Do something

// Some more description

// Some more

//+Access: virtual public

//+Returns: void

//+Qualifier:

//+Parameter:

//***********************************…



(2) then change any comment line which contains text but which does not start //+ to //!



//***********************************…

//

//+Method: ....

//+FullName: ....

//!Description: Do something

//!Some more description

//!Some more

//+Access: virtual public

//+Returns: void

//+Qualifier:

//+Parameter:

//***********************************…



(3) change all the "special" lines back to normal:



//***********************************…

//

// Method: ....

// FullName: ....

//!Description: Do something

//!Some more description

//!Some more

// Access: virtual public

// Returns: void

// Qualifier:

// Parameter:

//***********************************…
satsumo
2009-07-24 17:18:53 UTC
What a waste of time this is -



// Method: See function declaration, approx 6 lines down

// Description: This is the only useful bit of information

// Access: See function declaration, approx 4 lines down

// Returns: See function declaration, approx 3 lines down

// Qualifier:See function declaration, approx 2 lines down

// Parameter: See function declaration, approx 1 lines down



So often I see these chunks of (time consuming) text where the programmer hasn't bothered to describe what the function does, or what the parameters are. For example -



private:



// Method: StoreObjects

// Description: Stores the objects

// Access: private

// Returns: void

// Qualifier: none

// Parameter: Object *objects, pointer to objects

void StoreObjects (Object *objects);



6 lines of information that is obvious from looking at the function. While the opportunities to say something useful (in Description, or Parameter) are lost to pointless repetition.



It's a very MS way to do things, repeat the same information in a slightly different format. Just make things bigger without providing any return.
akangcupez
2009-07-22 09:50:03 UTC
you didn't say in specific which version of VS are you using. Anyway, this is the codes in VB:

"say you have 2 textboxes, one is storing your old text and another textbox is for new text"



Code:

TextBox2.Text = TextBox1.Text.Replace("//", "//!")



'that will change all "//" with new "//!" as you want


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...