RE: Embedding a Variable in a string C# Dotnet

  • From: "Jeff Berwick" <mailinglists@xxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 7 Jan 2009 20:29:41 -0500

Yes, you are right.  In the basic example I used for illustration, it
wouldn't be necessary.  However, in my program, where I need to create some
sql statements based on user selection, query the sqlite database and
generate a report in Excel, it would be very useful.  I will take a look at
reflection and see what I can come up with.

Thanks for the help!  I just didn't even know what terminology to use and my
Google searches, as a result, were not proving fruitful.

Jeff
 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
Sent: Wednesday, January 07, 2009 6:16 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Embedding a Variable in a string C# Dotnet

If you absolutely need to do this, which I question the need of in this
example, the methodology you wish to use is called reflection, if you look
up reflection you'll get exactly what you'd like.

Take care,
Sina 

________________________________

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jeff Berwick
Sent: Wednesday, January 07, 2009 6:13 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Embedding a Variable in a string C# Dotnet


Hi Listers,
 
Please bare with me while I attempt to explain what I want to do.
 
I want to build a string that has a variable name inside it.  Then, I want
to send that string to a function which will recognise the variable name,
embedded din the string, and replace it with its value.  Is this possible?
 
By way of an illustration:
 
private void stuff()
{
string firstname;
string lastname;
string result;
 
result = buildString();
MessageBox.Show(result.ToString());
}
 
private string buildString()
{
return "Here is the string with the two variables - firstname and lastname";
}
 
I also tried putting {} around the variable name but, as expected that
didn't work.  Any suggestions on an elegant solution?
 
Thx,
Jeff

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: