Re: simple gsub question \' \` what?
- From: Timothy Hunter <TimHunter@xxxxxxxxx>
- Date: Sat, 31 Mar 2007 06:39:52 +0900
Dustin Anderson wrote:
Sorry for the simple question, I just can't figure this out after aI'd use two calls to split:
couple hours...
I need to parse a string:
string = column-1:block-0,block-2,block-1,block-3
and I need to extract everything before the : (colon) into one variable
(should end up like this:
string1 = column-1
and then the rest of the string (block-0,block-2,block-1,block3) into an
array...
irb(main):001:0> string = 'column-1:block-0,block-2,block-1,block-3'
=> "column-1:block-0,block-2,block-1,block-3"
irb(main):002:0> string1, s = string.split(':')
=> ["column-1", "block-0,block-2,block-1,block-3"]
irb(main):003:0> string1
=> "column-1"
irb(main):004:0> string2 = s.split(',')
=> ["block-0", "block-2", "block-1", "block-3"]
irb(main):005:0>
You could probably turn that into a one-liner but that's just golfing.
.
- Follow-Ups:
- Re: simple gsub question \' \` what?
- From: Rob Biedenharn
- Re: simple gsub question \' \` what?
- References:
- simple gsub question \' \` what?
- From: Dustin Anderson
- simple gsub question \' \` what?
- Prev by Date: Re: simple gsub question \' \` what?
- Next by Date: What is wrong in my script?
- Previous by thread: Re: simple gsub question \' \` what?
- Next by thread: Re: simple gsub question \' \` what?
- Index(es):
Relevant Pages
|