473,387 Members | 1,504 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,387 software developers and data experts.

imbed variables in text inside of MessageBox(

Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write("Answer: {0}",answer);

But instead do it inside of a MessageBox.Show(

Thanks
Jan 24 '06 #1
7 16818
generallee5686,

You can always format the string before you make the call to Show. So,
you could do this:

string prompt = string.Format("Answer: {0}", answer);
MessageBox.Show(prompt);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"generallee5686" <u18038@uwe> wrote in message news:5ada7c985ce28@uwe...
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write("Answer: {0}",answer);

But instead do it inside of a MessageBox.Show(

Thanks

Jan 24 '06 #2
generallee5686,

MessageBox doesn't provide this out of the box, but it can be easily
workaround using String.Format method

Message.Box.Show(string.Format("Answer: {0}",answer"));
--
HTH
Stoitcho Goutsev (100)

"generallee5686" <u18038@uwe> wrote in message news:5ada7c985ce28@uwe...
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write("Answer: {0}",answer);

But instead do it inside of a MessageBox.Show(

Thanks

Jan 24 '06 #3
generallee5686 <u18038@uwe> wrote:
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write("Answer: {0}",answer);

But instead do it inside of a MessageBox.Show(


Use string.Format:

MessageBox.Show (string.Format ("Answer: {0}", answer),
...);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 24 '06 #4
Wow that helped tons guys.
Thanks so much!
Jan 24 '06 #5
I like to build a function that takes params....

private void ShowMsg(string fmt, params object[] prms)
{
MessageBox.Show(string.Format(fmt, prms));
}

ShowMsg("Answer: {0}", answer);

-mdb

Jon Skeet [C# MVP] <sk***@pobox.com> wrote in
news:MP************************@msnews.microsoft.c om:
generallee5686 <u18038@uwe> wrote:
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write("Answer: {0}",answer);

But instead do it inside of a MessageBox.Show(


Use string.Format:

MessageBox.Show (string.Format ("Answer: {0}", answer),
...);


Jan 24 '06 #6
Just another quick question about that.

So does like Console.Write have string.Format built into it or something?
Jan 25 '06 #7
generallee5686 <u18038@uwe> wrote:
Just another quick question about that.

So does like Console.Write have string.Format built into it or something?


Basically, yes. The overload
Console.Write (string, params object[])
calls through to TextWriter.Write(string, params object[])
which in turn calls string.Format.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 25 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fred Heida | last post by:
Hi, I try to implement dragging (and dropping) of text inside a rtf control (similar as word i guess) I have set AllowdDrop = true and setup the handlers for DragDrop, DragOver, DragEnter. is...
6
by: TomB | last post by:
Hello all, On the page located at http://deimos.curious.be/~dusk/lyrics.php#gotn I have put the lyrics text inside <pre> elements so that the UA renders the linebreaks in the code. Because...
1
by: Paul | last post by:
Hi all, I'm making a custom control. I can set attributes to determine how the control is rendered, but I don't know how to access the text inside the tag. For example: <tagprefix:TestControl...
4
by: Pete90 | last post by:
I am trying to change the text continously for the text inside a table but it stops after reaching the 2nd index in the array. Anyone can debug? Below are the coding: <script...
11
by: giannis | last post by:
How can i refer to a form's textbox.text inside a SQL clause ? I know how is that in Access* but at VB i receive error. * SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2=!.
2
by: amitp | last post by:
hi i'm using MS Word2003 for my VB application which is a report. The word documents contains tables and the cells inside the table contain some fields. My application replaces the field values with...
1
by: countocram | last post by:
I have big problem, I'm using preg_replace() function for my highlighter function, after searching for particular keyword, once the hightler check box is checked it will highlight the content that...
1
by: StanislavPetrov | last post by:
Is it possible to delete the text inside .txt file?And if so,how?
4
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi everydoby! I have an issue, I have an static image, and I need to write text inside it in runtime, but I don't know how! I can't use absolute position in atributtes style. Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.