Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 08, 2007 Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | 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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | 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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexander Panek | 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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | "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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Ohno | 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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | 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 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jari-Matti Mäkelä | 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 10, 2007 Re: Return ASCII value as uint | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Ohno | "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. |
Copyright © 1999-2021 by the D Language Foundation