473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Mass refactoring Console.WriteLine statements?

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
5 1377
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
8
by: Frank Rizzo | last post by:
I keep hearing this term thrown around. What does it mean in the context of code? Can someone provide a definition and example using concrete code? Thanks.
7
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
3
by: Roy Gourgi | last post by:
Hi, How would I set the width of lnSize to 6 in the statement Console.WriteLine("Size of {0} ", lnSize); Furthermore is there a way to combine these 3 statements into 1 ...
4
by: Dennis C. Drumm | last post by:
I've noticed that using Console.WriteLine statements to debug a Windows Forms Application will sometimes write output to the VS 2005 Output window and sometimes it doesn't. I know that...
4
by: Michael D. Ober | last post by:
Is there anyway the VB Compiler can detect if a program is a console application? I have some libraries that need to write to the console if the program is a console app. Thanks, Mike Ober.
1
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following...
4
by: shapper | last post by:
Hello, Where can I see the output of console.writeline(MyVar) in VS 2005? And do I need to debug or just run it? Is there any other way to check the a variable value? Thanks,
1
by: mquincey | last post by:
One of the features offered by .NET 2.0 is the use of the TraceSource class. In an attempt to demonstrate its use, I wanted to run my test under the following conditions: 1. Use TraceSource class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.