Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getting end of string

17 views
Skip to first unread message

Simon Krahnke

unread,
Apr 24, 2013, 10:09:23 AM4/24/13
to
Hi,

I have a string s and I'm only interested in everything in it after the
first character.

So at the moment I do

| s[1,128].bytes

Just putting 128 as the length cause that's probably bigger than
anything I'll ever enter into my tool. But there's gotta be a better way
of doing that except going to Regexps.

mfg, simon .... confused

Doc O'Leary

unread,
Apr 24, 2013, 12:13:53 PM4/24/13
to
In article <87txmwc...@xts.gnuu.de>,
Depending on your needs, these spring to mind:

>> here = "this is a string for you"
=> "this is a string for you"
>> here[1,here.length]
=> "his is a string for you"
>> here[1..-1]
=> "his is a string for you"
>> here[0] = ""
=> ""
>> here
=> "his is a string for you"

--
iPhone apps that matter: http://appstore.subsume.com/
My personal UDP list: 127.0.0.1, localhost, googlegroups.com, theremailer.net,
and probably your server, too.

Simon Krahnke

unread,
Apr 25, 2013, 8:16:46 AM4/25/13
to
* Doc O'Leary <drolear...@2q2013.subsume.com> (18:13) schrieb:

>In article <87txmwc...@xts.gnuu.de>,
> Simon Krahnke <over...@gmx.li> wrote:
>
>> I have a string s and I'm only interested in everything in it after the
>> first character.
>>
>> So at the moment I do
>>
>> | s[1,128].bytes
>>
>> Just putting 128 as the length cause that's probably bigger than
>> anything I'll ever enter into my tool. But there's gotta be a better way
>> of doing that except going to Regexps.
>
> Depending on your needs, these spring to mind:
>
>>> here = "this is a string for you"
>=> "this is a string for you"
>>> here[1,here.length]
>=> "his is a string for you"
>>> here[1..-1]

Thank you, I like this one. Didn't come to my mind, that the Range would
do it.

>=> "his is a string for you"
>>> here[0] = ""
>=> ""
>>> here
>=> "his is a string for you"

It's the start of a chain of operations in one line. Likes this:

| when /^h/ then s[1..-1].scan(/../).map { | d | d.hex }

mfg, simon .... binshow.rb replaces binshow.pl
0 new messages