Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert Int To String ??

0 views
Skip to first unread message

pm

unread,
Jun 19, 2002, 10:51:28 AM6/19/02
to
Hello,
I'm a C# beginner, and if someone could translate these Jbuilder Lines in
C#, it would help me:

String st=new String();
st=st.valueOf(MyIntVar+1);
if (MyIntVarr+1<=9)
st="0"+st;

Thanks a lot !

Nicholas Paldino [.NET/C# MVP]

unread,
Jun 19, 2002, 11:01:57 AM6/19/02
to
pm,

To convert a number to a string, you can just call the ToString method
on the number in most cases, like so:

// Assign the number.
int pintNumber = 10;

// Get the string representation.
string pstrNumber = pintNumber.ToString();

Hope this helps.


--
- Nicholas Paldino [.NET MVP]
- nicholas...@exisconsulting.com


"pm" <p...@nst.fr> wrote in message news:OzwX8C6FCHA.2772@tkmsftngp13...

Greg Ewing

unread,
Jun 19, 2002, 11:04:02 AM6/19/02
to
pm, check out the ToString method on almost any datatype.

string st = "";
int MyIntVar = 8;
//you can convert an int to a string and ensure that your string will show a
leading 0 with this one line of code
st = MyIntVar.ToString("00");

--
Greg
http://www.claritycon.com/

"pm" <p...@nst.fr> wrote in message news:OzwX8C6FCHA.2772@tkmsftngp13...

pm

unread,
Jun 19, 2002, 11:11:30 AM6/19/02
to
It's ok for me
Thanks.

"pm" <p...@nst.fr> a écrit dans le message de news:
OzwX8C6FCHA.2772@tkmsftngp13...

Chris R

unread,
Jun 19, 2002, 11:22:03 AM6/19/02
to
Simple:

String st = ( MyIntVar+1 ).ToString("00");

Chris R.

"pm" <p...@nst.fr> wrote in message news:OzwX8C6FCHA.2772@tkmsftngp13...

Otis Mukinfus

unread,
Jun 19, 2002, 8:51:21 PM6/19/02
to

int myvar = 1;
myvar += 1;
string st = myvar.ToString();
if((myvar + 1) <= 9)
st = "0" + myvar.ToString();


Otis M.
http://www.arltex.com
http://www.otismukinfus.com

0 new messages