digitalmars.D.learn - Return ASCII value as uint
- okibi (3/3) May 08 2007 Hey,
- Johan Granberg (2/8) May 08 2007 You could just assign the charachter to a uint variabel, that should wor...
- Alexander Panek (5/11) May 08 2007 Shouldn't a cast be sufficiant?
- okibi (4/18) May 08 2007 Yes, a cast would work, however I was wondering if there was an actual f...
- Jarrett Billingsley (4/6) May 08 2007 Just cast it. chars are just integers; you can freely cast between
- John Ohno (5/14) May 08 2007 A good general template function (will work for anything that can be exp...
- okibi (2/19) May 08 2007 Well, that doesn't compile. Is the ! needed? Anyways, if I pass an "s" t...
- Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= (2/9) May 08 2007 That ! is a typo.
- okibi (4/14) May 08 2007 I thought it was, works great without it!
-
Stewart Gordon
(6/11)
May 10 2007
"John Ohno"
wrote in message -
Bill Baxter
(8/22)
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: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?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
"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...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); }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
John Ohno Wrote:Jarrett Billingsley Wrote: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?"okibi" <okibi ratedo.com> wrote in message news:f1q8ne$3147$1 digitalmars.com...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); }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
okibi wrote:John Ohno Wrote:That ! is a typo.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
Jari-Matti Mäkelä Wrote:okibi wrote:I thought it was, works great without it! Thanks, OkibiJohn Ohno Wrote:That ! is a typo.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
"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><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)). --bbA 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