digitalmars.D.learn - Return ASCII value as uint
- okibi <okibi ratedo.com> May 08 2007
- Johan Granberg <lijat.meREM OVEgmail.com> May 08 2007
- Alexander Panek <alexander.panek brainsware.org> May 08 2007
- okibi <okibi ratedo.com> May 08 2007
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> May 08 2007
- John Ohno <john.ohno gmail.com> May 08 2007
- okibi <okibi ratedo.com> May 08 2007
- Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> May 08 2007
- okibi <okibi ratedo.com> May 08 2007
- "Stewart Gordon" <smjg_1998 yahoo.com> May 10 2007
- Bill Baxter <dnewsgroup billbaxter.com> May 10 2007
Hey, I was wondering if D has a simple function to return the ASCII value of a character as a uint, much like ord() does in php. Thanks!
May 08 2007
okibi wrote:Hey, I was wondering if D has a simple function to return the ASCII value of a character as a uint, much like ord() does in php. Thanks!
You could just assign the charachter to a uint variabel, that should work.
May 08 2007
On Tue, 08 May 2007 11:27:40 -0400 okibi <okibi ratedo.com> wrote:Hey, I was wondering if D has a simple function to return the ASCII value of a character as a uint, much like ord() does in php. Thanks!
Shouldn't a cast be sufficiant? char c = 'a'; uint i = cast(uint)c;
May 08 2007
Alexander Panek Wrote:On Tue, 08 May 2007 11:27:40 -0400 okibi <okibi ratedo.com> wrote:Hey, I was wondering if D has a simple function to return the ASCII value of a character as a uint, much like ord() does in php. Thanks!
Shouldn't a cast be sufficiant? char c = 'a'; uint i = cast(uint)c;
Yes, a cast would work, however I was wondering if there was an actual function that I could use to grab the value while passing it to another function, specifically this function: saveItem.addAccelerator("activate",accelGroup,i,GdkModifierType.CONTROL_MASK,accelFlags); That function contains the i variable from your function. Is there a simple function, or should I use a cast?
May 08 2007
"okibi" <okibi ratedo.com> wrote in message news:f1q8ne$3147$1 digitalmars.com...That function contains the i variable from your function. Is there a simple function, or should I use a cast?
Just cast it. chars are just integers; you can freely cast between characters and integers.
May 08 2007
Jarrett Billingsley Wrote:"okibi" <okibi ratedo.com> wrote in message news:f1q8ne$3147$1 digitalmars.com...That function contains the i variable from your function. Is there a simple function, or should I use a cast?
Just cast it. chars are just integers; you can freely cast between characters and integers.
A good general template function (will work for anything that can be explicity casted to uint, including chars, doubles, and pointers): uint toUint!(T)(T c) { return (cast(uint)c); }
May 08 2007
John Ohno Wrote:Jarrett Billingsley Wrote:"okibi" <okibi ratedo.com> wrote in message news:f1q8ne$3147$1 digitalmars.com...That function contains the i variable from your function. Is there a simple function, or should I use a cast?
Just cast it. chars are just integers; you can freely cast between characters and integers.
A good general template function (will work for anything that can be explicity casted to uint, including chars, doubles, and pointers): uint toUint!(T)(T c) { return (cast(uint)c); }
Well, that doesn't compile. Is the ! needed? Anyways, if I pass an "s" to that, it should return the ASCII value (115 I think), right?
May 08 2007
okibi wrote:John Ohno Wrote:uint toUint!(T)(T c) { return (cast(uint)c); }
Well, that doesn't compile. Is the ! needed? Anyways, if I pass an "s" to that, it should return the ASCII value (115 I think), right?
That ! is a typo.
May 08 2007
Jari-Matti Mäkelä Wrote:okibi wrote:John Ohno Wrote:uint toUint!(T)(T c) { return (cast(uint)c); }
Well, that doesn't compile. Is the ! needed? Anyways, if I pass an "s" to that, it should return the ASCII value (115 I think), right?
That ! is a typo.
I thought it was, works great without it! Thanks, Okibi
May 08 2007
"John Ohno" <john.ohno gmail.com> wrote in message news:f1q9n0$1bd$1 digitalmars.com... <snip>A good general template function (will work for anything that can be explicity casted to uint, including chars, doubles, and pointers): uint toUint!(T)(T c) { return (cast(uint)c); }
Is there really any point using this when you can just cast when you need to? OK, so it saves two characters where it's used.... Stewart.
May 10 2007
Stewart Gordon wrote:"John Ohno" <john.ohno gmail.com> wrote in message news:f1q9n0$1bd$1 digitalmars.com... <snip>A good general template function (will work for anything that can be explicity casted to uint, including chars, doubles, and pointers): uint toUint!(T)(T c) { return (cast(uint)c); }
Is there really any point using this when you can just cast when you need to? OK, so it saves two characters where it's used.... Stewart.
<con> It makes someone have to go lookup what toUint actually does. Rather than being able to tell immediately by virtue of knowing basic D syntax. <pro> toUint(3+foo(x)) is a little easier on the eyes than cast(uint)(3+foo(x)). --bb
May 10 2007









Johan Granberg <lijat.meREM OVEgmail.com> 