By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,912 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,912 IT Pros & Developers. It's quick & easy.

Mass refactoring Console.WriteLine statements?

P: n/a
Hi all,

Throughout my code, I have lines like this:
Console.WriteLine("This is a sample with three variables: " + a + " and " + b + " and " + c);

Are there any VS2005 IDE plugins or utilities that would let me convert them all easily to this:
Console.WriteLine("This is a sample with three variables: {0} and {1} and {2}", a,b,c);

Thanks in advance!

Adam
Jan 22 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Adam,

I'm not aware of any plugins for VS to do this (although I wouldn't be surprised if there are some), but it shouldn't take too long for you to build a WinForms app with the RegularExpressions classes that will do this kind of search-and-replace that you can run on a directory of files. I'd say it shouldn't take much longer than 30 mins to build, so if that is less time than it would take you to manually make the changes, it might be worth it.

Cheers,
Peter

Peter McMahon
http://www.dotnet.za.net

"AdamM" <no****@nospam.com> wrote in message news:us******************************@comcast.com. ..
Hi all,

Throughout my code, I have lines like this:
Console.WriteLine("This is a sample with three variables: " + a + " and " + b + " and " + c);

Are there any VS2005 IDE plugins or utilities that would let me convert them all easily to this:
Console.WriteLine("This is a sample with three variables: {0} and {1} and {2}", a,b,c);

Thanks in advance!

Adam
Jan 22 '06 #2

P: n/a
Couldn't you do this with Search/Replace in Files?

search: "three variables: " + a + " and " + b + " and " + c);"

replace: "three variables: {0} and {1} and {2}", a,b,c);"

??
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"AdamM" wrote:
Hi all,

Throughout my code, I have lines like this:
Console.WriteLine("This is a sample with three variables: " + a + " and " + b + " and " + c);

Are there any VS2005 IDE plugins or utilities that would let me convert them all easily to this:
Console.WriteLine("This is a sample with three variables: {0} and {1} and {2}", a,b,c);

Thanks in advance!

Adam

Jan 22 '06 #3

P: n/a
Actually, that was just an example line. There are thousands of lines like
this, but none are duplicates. They all say different things with different
variable names and numbers of variables used. So simple search and replace
won't work for us.

I was looking for some formatting tools or anything that might allow me to
straighten these out for localization purposes en-mass.

Cheers!
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:8D**********************************@microsof t.com...
Couldn't you do this with Search/Replace in Files?

search: "three variables: " + a + " and " + b + " and " + c);"

replace: "three variables: {0} and {1} and {2}", a,b,c);"

??
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"AdamM" wrote:
Hi all,

Throughout my code, I have lines like this:
Console.WriteLine("This is a sample with three variables: " + a + " and "
+ b + " and " + c);

Are there any VS2005 IDE plugins or utilities that would let me convert
them all easily to this:
Console.WriteLine("This is a sample with three variables: {0} and {1} and
{2}", a,b,c);

Thanks in advance!

Adam

Jan 23 '06 #4

P: n/a
1) Why? The former is much more efficient.
2) I know of no reason to prefer Console.WriteLine over Trace or Debug and
many good reasons to prefer Trace over Console

"AdamM" <no****@nospam.com> wrote in message
news:us******************************@comcast.com. ..
Hi all,

Throughout my code, I have lines like this:
Console.WriteLine("This is a sample with three variables: " + a + " and " +
b + " and " + c);

Are there any VS2005 IDE plugins or utilities that would let me convert them
all easily to this:
Console.WriteLine("This is a sample with three variables: {0} and {1} and
{2}", a,b,c);

Thanks in advance!

Adam
Jan 23 '06 #5

P: n/a
Hi,

Not that I know about, but IMO the time/resources you have/will expend for find it will not justify the possible performance improvement. improvements that I'm not even sure will happens

unless you have it inside some loop just let it like that.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"AdamM" <no****@nospam.com> wrote in message news:us******************************@comcast.com. ..
Hi all,

Throughout my code, I have lines like this:
Console.WriteLine("This is a sample with three variables: " + a + " and " + b + " and " + c);

Are there any VS2005 IDE plugins or utilities that would let me convert them all easily to this:
Console.WriteLine("This is a sample with three variables: {0} and {1} and {2}", a,b,c);

Thanks in advance!

Adam
Jan 23 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.