From: 7stud -- Date: 2009-09-10T14:47:24+09:00 Subject: Re: string.each Bigmac Turdsplash wrote: > 7stud -- wrote: >> Bigmac Turdsplash wrote: >>> after i split the string, how can i put the string back into its >>> original form? >> >> str = ["hello", "my", "name", "is", "bigmac"].join(" ") >> puts str >> >> --output:-- >> hello my name is bigmac > > lets say im reading a string from a socket and its super long, i want to > trim the first word from the string then do something with the rest of > the string... > > str = "disaster a bunch of junk. 98rh98rh98ujvi".split > > puts str[1] # idetify the first word, > > puts str[2 threw X].join(" ") # takes the rest of the string and prints > to screen in its original form... > > > but how do i know what X is? (until end of string) X = -1 arr = [10, 20, 30, 40] p arr[1..-1] --output:-- [20, 30, 40] But instead of splitting a super long string and then re-joining it, you can just split off the first word like this: str = "a really long string" first_word, the_rest = str.split(" ", 2) p first_word p the_rest --output:-- "a" "really long string" -- Posted via http://www.ruby-forum.com/.