-
March 16th, 2007, 01:27 AM
#1
[RESOLVED] How to convert integer to string in C#
Hello all.
I am developing a code in which I need to convert int to string. Plz help...
-
March 16th, 2007, 01:58 AM
#2
Re: How to convert integer to string in C#
Hi,
Like this:
Code:
String number;
int x = 10;
number = x.ToString();
Regards,
Laitinen
-
March 16th, 2007, 02:02 AM
#3
Re: How to convert integer to string in C#
Or
Code:
int x = 10;
string xstring = Convert.ToString(x);
MessageBox.Show(xstring);
VS 2005
-
March 16th, 2007, 02:08 AM
#4
Re: How to convert integer to string in C#
This is the code...
asset_file_list += "\n<asset size=" + asset_file_size + " count=" + asset_file_count + ">\n";
here i want that "asset_file_list" variable should get the value like
<asset size="517361" count="11">
but its giving...
<asset size=517361 count=11>
Plz check and give support...
-
March 16th, 2007, 02:14 AM
#5
Re: How to convert integer to string in C#
Code:
asset_file_list += "\n<asset size=" + asset_file_size.ToString() + " count=" + asset_file_count.ToString() + ">\n";
-
March 16th, 2007, 02:17 AM
#6
Re: How to convert integer to string in C#
This is not working...Giving the same output as above mensioned. I tried this earlier...
-
March 16th, 2007, 02:39 AM
#7
Re: How to convert integer to string in C#
Do you really want the output to look like this:
<asset size="517361" count="11">
assuming that asset_file_size and asset_file_count is already a string,
Code:
asset_file_list += "\n<asset size=" + "\"" + asset_file_size + "\"" + " count=" + "\""+ asset_file_count + "\"" + ">\n";
otherwise do this:
Code:
asset_file_list += "\n<asset size=" + "\"" + asset_file_size.ToString() + "\"" + " count=" + "\""+ asset_file_count.ToString() + "\"" + ">\n";
-
March 16th, 2007, 02:46 AM
#8
Re: How to convert integer to string in C#
you've got to wonder how some folks make it out of bed given gravity's strong pull...
-
March 16th, 2007, 02:51 AM
#9
Re: How to convert integer to string in C#
When I am using
-----------------------------------------------------------------------------------------------------
asset_file_list += "\n<asset size=" + "\"" + asset_file_size + "\"" + " count=" + "\""+ asset_file_count + "\"" + ">\n";
----------------------------------------------------------------------------------------------------
I am getting the output:
"\n<asset size=\"10911\" count=\"1\">\n"
When I am using
-----------------------------------------------------------------------------------------------------
asset_file_list += "\n<asset size=" + "\"" + asset_file_size.ToString() + "\"" + " count=" + "\""+ asset_file_count.ToString() + "\"" + ">\n";
----------------------------------------------------------------------------------------------------
I am getting the output:
"\n<asset size=\"10911\" count=\"1\">\n"
Expected output:
<asset size="10911" count="1">
-
March 16th, 2007, 02:54 AM
#10
Re: How to convert integer to string in C#
Where are you getting that output? If you see it in the debug window, then you have to take a look at the "Text Visualizer" and I am sure you will get the expected result.
This code works perfect in a multiline textbox;
Code:
string asset_file_list = "";
int asset_file_size = 517361;
int asset_file_count = 11;
asset_file_list += "\r\n<asset size=\"" + asset_file_size.ToString() + "\" count=\"" + asset_file_count.ToString() + "\">\r\n";
textBox1.Text = asset_file_list;
Regards,
Laitinen
Last edited by laitinen; March 16th, 2007 at 02:57 AM.
-
March 16th, 2007, 02:54 AM
#11
Re: How to convert integer to string in C#
are you perhaps looking in the watch window and not at your actual output???
-
March 16th, 2007, 04:18 AM
#12
Re: How to convert integer to string in C#
Thank you all...Problem is solved...
-
March 24th, 2014, 02:42 AM
#13
Re: [RESOLVED] How to convert integer to string in C#
For anyone who's curious about the fastest way to convert an int to a string, you can read this webpage (http://cc.davelozinski.com/c-sharp/f...-int-to-string).
Basically it's a toss up between:
.ToString()
Convert.ToString()
until you get to about 21 million conversions.
The code is there too if you want to run it on your own system.
Good luck!
Last edited by FireMyst; July 5th, 2014 at 07:27 AM.
Reason: Updated link since it was out of date.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|