Jump to page: 1 2
Thread overview
Get Character At?
Apr 24, 2007
okibi
Apr 24, 2007
Derek Parnell
Apr 24, 2007
okibi
Apr 24, 2007
okibi
Apr 24, 2007
BCS
Apr 24, 2007
okibi
Apr 24, 2007
Clay Smith
Apr 24, 2007
Clay Smith
Apr 24, 2007
Derek Parnell
Apr 25, 2007
Daniel Keep
Apr 25, 2007
Derek Parnell
Apr 25, 2007
Frits van Bommel
Apr 25, 2007
Daniel Keep
Apr 25, 2007
Derek Parnell
Apr 25, 2007
Frits van Bommel
April 24, 2007
Is there a getCharAt() function for D?

Thanks!
April 24, 2007
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
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
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
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
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
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
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
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
Clay Smith wrote:
> 
> text[5] will return the sixth element in the array.

He never said anything about getCharAt starting at one...
« First   ‹ Prev
1 2