Thread overview | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 24, 2007 Get Character At? | ||||
---|---|---|---|---|
| ||||
Is there a getCharAt() function for D? Thanks! |
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | On Tue, 24 Apr 2007 10:30:16 -0400, okibi wrote: > Is there a getCharAt() function for D? Get a character from what? A string, a file, a console screen, ... ? -- Derek Parnell Melbourne, Australia "Justice for David Hicks!" skype: derek.j.parnell |
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell Wrote:
> On Tue, 24 Apr 2007 10:30:16 -0400, okibi wrote:
>
> > Is there a getCharAt() function for D?
>
> Get a character from what? A string, a file, a console screen, ... ?
>
> --
> Derek Parnell
> Melbourne, Australia
> "Justice for David Hicks!"
> skype: derek.j.parnell
Such as this:
char[] text = "This is a test sentence.";
int loc = 5;
char num5 = text.getCharAt(loc);
Something along those lines.
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | okibi wrote:
> Derek Parnell Wrote:
>
>> On Tue, 24 Apr 2007 10:30:16 -0400, okibi wrote:
>>
>> > Is there a getCharAt() function for D?
>>
>> Get a character from what? A string, a file, a console screen, ... ?
>>
>> --
>> Derek Parnell
>> Melbourne, Australia
>> "Justice for David Hicks!"
>> skype: derek.j.parnell
>
> Such as this:
>
> char[] text = "This is a test sentence.";
>
> int loc = 5;
>
> char num5 = text.getCharAt(loc);
>
> Something along those lines.
Why not just do:
char[] text = "some text";
char num5 = text[5];
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | okibi wrote:
> Derek Parnell Wrote:
>
>> On Tue, 24 Apr 2007 10:30:16 -0400, okibi wrote:
>>
>>> Is there a getCharAt() function for D?
>> Get a character from what? A string, a file, a console screen, ... ?
>>
>> --
>> Derek Parnell
>> Melbourne, Australia
>> "Justice for David Hicks!"
>> skype: derek.j.parnell
>
> Such as this:
>
> char[] text = "This is a test sentence.";
>
> int loc = 5;
>
> char num5 = text.getCharAt(loc);
>
> Something along those lines.
>
Just use
char num5 = text[loc-1];
?
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomas Lindquist Olsen | Tomas Lindquist Olsen Wrote:
> okibi wrote:
>
> > Derek Parnell Wrote:
> >
> >> On Tue, 24 Apr 2007 10:30:16 -0400, okibi wrote:
> >>
> >> > Is there a getCharAt() function for D?
> >>
> >> Get a character from what? A string, a file, a console screen, ... ?
> >>
> >> --
> >> Derek Parnell
> >> Melbourne, Australia
> >> "Justice for David Hicks!"
> >> skype: derek.j.parnell
> >
> > Such as this:
> >
> > char[] text = "This is a test sentence.";
> >
> > int loc = 5;
> >
> > char num5 = text.getCharAt(loc);
> >
> > Something along those lines.
>
> Why not just do:
>
> char[] text = "some text";
> char num5 = text[5];
>
>
Because it isn't working for me. That was what I was trying to do seeing as char[] is simply an array of characters. However, it's returning an int and not a char.
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | okibi wrote:
>
>
> Because it isn't working for me. That was what I was trying to do seeing as char[] is simply an array of characters. However, it's returning an int and not a char.
How about a little more code. What I've seen so far should work.
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to okibi | okibi wrote:
>>
>> Why not just do:
>>
>> char[] text = "some text";
>> char num5 = text[5];
>>
>>
>
> Because it isn't working for me. That was what I was trying to do seeing as char[] is simply an array of characters. However, it's returning an int and not a char.
import std.stdio;
void main()
{
char[] text = "this is a sentence";
int loc = 5;
writefln("%s", typeid(typeof(text[loc])));
}
this prints 'char' as expected...
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomas Lindquist Olsen | Tomas Lindquist Olsen wrote:
> okibi wrote:
>
>> Derek Parnell Wrote:
>>
>>> On Tue, 24 Apr 2007 10:30:16 -0400, okibi wrote:
>>>
>>>> Is there a getCharAt() function for D?
>>> Get a character from what? A string, a file, a console screen, ... ?
>>>
>>> --
>>> Derek Parnell
>>> Melbourne, Australia
>>> "Justice for David Hicks!"
>>> skype: derek.j.parnell
>> Such as this:
>>
>> char[] text = "This is a test sentence.";
>>
>> int loc = 5;
>>
>> char num5 = text.getCharAt(loc);
>>
>> Something along those lines.
>
> Why not just do:
>
> char[] text = "some text";
> char num5 = text[5];
>
text[5] will return the sixth element in the array.
|
April 24, 2007 Re: Get Character At? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Clay Smith | Clay Smith wrote:
>
> text[5] will return the sixth element in the array.
He never said anything about getCharAt starting at one...
|
Copyright © 1999-2021 by the D Language Foundation