Prev: looking for the method like postmessage in win32.
Next: LINQ - Picking the most recently created file
From: Jeff Johnson on 15 Mar 2010 16:22 "sahel" <nam.nam.barooon(a)gmail.com> wrote in message news:e8722a56-827e-4d6f-a20a-876f8b4db2b0(a)x12g2000yqx.googlegroups.com... > i want this answer because i want to get some char from user like > this : y=(x^2)+1 so i will put 2 in char but to write the program for > it that it must do an math question ,program must know that 2 & 1 are > not char they are int Subtract 48 from each digit that you convert from char to int and you'll have what you want. Of course, that's the long way. There's also the Convert class or the int.Parse() / int.TryParse() methods.
From: Andrew Poelstra on 15 Mar 2010 16:37 On 2010-03-15, Jeff Johnson <i.get(a)enough.spam> wrote: > "sahel" <nam.nam.barooon(a)gmail.com> wrote in message > news:e8722a56-827e-4d6f-a20a-876f8b4db2b0(a)x12g2000yqx.googlegroups.com... > >> i want this answer because i want to get some char from user like >> this : y=(x^2)+1 so i will put 2 in char but to write the program for >> it that it must do an math question ,program must know that 2 & 1 are >> not char they are int > > Subtract 48 from each digit that you convert from char to int and you'll > have what you want. Of course, that's the long way. There's also the Convert > class or the int.Parse() / int.TryParse() methods. > Or subtract '0' and you'll not only be clearer, your code will work outside of ASCII-based encodings. -- Andrew Poelstra http://www.wpsoftware.net/andrew
From: Arne Vajhøj on 15 Mar 2010 20:26 On 15-03-2010 16:37, Andrew Poelstra wrote: > On 2010-03-15, Jeff Johnson<i.get(a)enough.spam> wrote: >> "sahel"<nam.nam.barooon(a)gmail.com> wrote in message >> news:e8722a56-827e-4d6f-a20a-876f8b4db2b0(a)x12g2000yqx.googlegroups.com... >>> i want this answer because i want to get some char from user like >>> this : y=(x^2)+1 so i will put 2 in char but to write the program for >>> it that it must do an math question ,program must know that 2& 1 are >>> not char they are int >> >> Subtract 48 from each digit that you convert from char to int and you'll >> have what you want. Of course, that's the long way. There's also the Convert >> class or the int.Parse() / int.TryParse() methods. > > Or subtract '0' and you'll not only be clearer, your code will > work outside of ASCII-based encodings. It will work with encoding where the digits are in order. But EBCDIC is not that common in .NET programs. But the readability argument is still valid. Arne
From: Arne Vajhøj on 15 Mar 2010 20:28 On 15-03-2010 09:30, sahel wrote: > i want this answer because i want to get some char from user like > this : y=(x^2)+1 so i will put 2 in char but to write the program for > it that it must do an math question ,program must know that 2& 1 are > not char they are int If you want to read and interpret an expression in a string, then note that it is more complex than simple char-int conversions. Arne
From: Göran Andersson on 17 Mar 2010 05:13 Arne Vajh�j wrote: > On 15-03-2010 16:37, Andrew Poelstra wrote: >> On 2010-03-15, Jeff Johnson<i.get(a)enough.spam> wrote: >>> "sahel"<nam.nam.barooon(a)gmail.com> wrote in message >>> news:e8722a56-827e-4d6f-a20a-876f8b4db2b0(a)x12g2000yqx.googlegroups.com... >>> >>>> i want this answer because i want to get some char from user like >>>> this : y=(x^2)+1 so i will put 2 in char but to write the program for >>>> it that it must do an math question ,program must know that 2& 1 are >>>> not char they are int >>> >>> Subtract 48 from each digit that you convert from char to int and you'll >>> have what you want. Of course, that's the long way. There's also the >>> Convert >>> class or the int.Parse() / int.TryParse() methods. >> >> Or subtract '0' and you'll not only be clearer, your code will >> work outside of ASCII-based encodings. > > It will work with encoding where the digits are in order. > > But EBCDIC is not that common in .NET programs. > > But the readability argument is still valid. > > Arne > A char always contain a Unicode character, it's not encoded. -- G�ran Andersson _____ http://www.guffa.com
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: looking for the method like postmessage in win32. Next: LINQ - Picking the most recently created file |