Re: simple gsub question \' \` what?



Hello,

you could just use split:

split = string.split(':')
string1 = split[0]
string2 = split[1].split(',')

-- Kristoffer


On 3/30/07, Dustin Anderson <rubyforum@xxxxxxxxxxxxxxxxxx> wrote:
Sorry for the simple question, I just can't figure this out after a
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...

How can I use gsub to extract everything before the colon?

I've looked at the documentation and just can't understand how to use
the \` or \' syntax... I want the two new strings to be:

string1 = column-1
string2 = ["block-0", "block-2", "block-1", "block-3"]

I'm thinking it's something like this:

string.gsub(/:/, "\`")

really, I just don't get it...

the documentation that I'm looking at is here:
http://dev.rubycentral.com/ref/ref_c_string.html

thanks a bunch!
-Dustin

--
Posted via http://www.ruby-forum.com/.




--
Kristoffer Lundén
✉ kristoffer.lunden@xxxxxxxxx
✉ kristoffer.lunden@xxxxxxxxxxxx
http://www.gamemaker.nu/
☎ 0704 48 98 77


Relevant Pages

  • RE: SQL Replace Function for Strings
    ... The solution is to find the position of the colon and than extract the string using this value from all values. ... For SQL: select KSName, SUBSTRING+1,1000) from job ...
    (microsoft.public.sqlserver.mseq)
  • Re: simple gsub question ` what?
    ... I need to parse a string: ... and I need to extract everything before the: (colon) into one variable ...
    (comp.lang.ruby)
  • simple gsub question ` what?
    ... I need to parse a string: ... How can I use gsub to extract everything before the colon? ... I've looked at the documentation and just can't understand how to use ...
    (comp.lang.ruby)
  • Re: simple gsub question ` what?
    ... I need to parse a string: ... How can I use gsub to extract everything before the colon? ...
    (comp.lang.ruby)
  • Re: How do I pull the info from this PostScript?
    ... Do you just want to extract the title from a file, ... When anchorsearch returns true, the 'post' string ... SourceArrayDecode filter from the array, and cvx exec the filter. ...
    (comp.lang.postscript)