Easier way to get a character of a string at some index

View: New views
5 Messages — Rating Filter:   Alert me  

Easier way to get a character of a string at some index

by ZuLuuuuuu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

For example, I want to get the third character of string "Hello". I
write something like this:

"Hello" at(2) asCharacter

This is of course not that hard but I should append asCharacter
message because I want to get the letter and not the byte presentation
of it. Is this the easiest way of getting characters or is there a
single message to get a character at some index?


Re: Easier way to get a character of a string at some index

by Jeremy Tregunna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sequence squareBrackets := method(i, at(i) asCharacter)
"foobar"[0] == "f"

--
Jeremy Tregunna
jtregunna@...



On 16-Jun-08, at 12:33 PM, Canol Gökel wrote:

> Hello,
>
> For example, I want to get the third character of string "Hello". I
> write something like this:
>
> "Hello" at(2) asCharacter
>
> This is of course not that hard but I should append asCharacter
> message because I want to get the letter and not the byte presentation
> of it. Is this the easiest way of getting characters or is there a
> single message to get a character at some index?
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>


Re: Easier way to get a character of a string at some index

by ZuLuuuuuu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- In iolanguage@..., Canol Gökel <canol@...> wrote:

>
> Hello,
>
> For example, I want to get the third character of string "Hello". I
> write something like this:
>
> "Hello" at(2) asCharacter
>
> This is of course not that hard but I should append asCharacter
> message because I want to get the letter and not the byte presentation
> of it. Is this the easiest way of getting characters or is there a
> single message to get a character at some index?
>

Also one another question, I want to change for example the second
letter with another one, can I write something else instead of the
code below:

"Hello" asMutable atPut(1, "d" at(0))

Especially instead of the "d" at(0) part.


Re: Easier way to get a character of a string at some index

by ZuLuuuuuu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- In iolanguage@..., Jeremy Tregunna <jtregunna@...> wrote:

>
> Sequence squareBrackets := method(i, at(i) asCharacter)
> "foobar"[0] == "f"
>
> --
> Jeremy Tregunna
> jtregunna@...
>
>
>
> On 16-Jun-08, at 12:33 PM, Canol Gökel wrote:
>
> > Hello,
> >
> > For example, I want to get the third character of string "Hello". I
> > write something like this:
> >
> > "Hello" at(2) asCharacter
> >
> > This is of course not that hard but I should append asCharacter
> > message because I want to get the letter and not the byte presentation
> > of it. Is this the easiest way of getting characters or is there a
> > single message to get a character at some index?
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
>

Thanks for the quick reply :)


Re: Easier way to get a character of a string at some index

by Jesse Ross-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> For example, I want to get the third character of string  
>>>>> "Hello". I
>>>>> write something like this:
>>>>>
>>>>> "Hello" at(2) asCharacter
>>>>>
>>>>> This is of course not that hard but I should append asCharacter
>>>>> message because I want to get the letter and not the byte  
>>>>> presentation
>>>>> of it. Is this the easiest way of getting characters or is there a
>>>>> single message to get a character at some index?

>> Sequence squareBrackets := method(i, at(i) asCharacter)
>> "foobar"[0] == "f"

If you don't want to redefine the squareBrackets, you could just make  
a regular method, something like:

Sequence charAt := method(i, at(i) asCharacter)
"foobar" charAt(0) == "f"



J.