1) I read lines from a file and put them into one string. There are many
empty sapces within the string. Which method is used to remove the
spaces? I try gsub!("\s",'') but it doesn't work. Any help will be
appreciated.
2) I read each line from a file and split each of them into several
fields/segments. Then I need to populate an array with one field only
from each line. How do I do that? I know do these in Perl but have no
idea using Ruby.
3) How do I search help or some methods/predifined variables from ruby
command prompt? Is it possible to do that? Right now the only thing I
can do is to open the folder containing the manual and read them in IE
browser. Is this the Ruby way?
1) I read lines from a file and put them into one string. There are many
empty sapces within the string. Which method is used to remove the
spaces? I try gsub!("\s",'') but it doesn't work. Any help will be
appreciated.
Try gsub(/\s/, '')
2) I read each line from a file and split each of them into several
fields/segments. Then I need to populate an array with one field only
from each line. How do I do that? I know do these in Perl but have no
idea using Ruby.
Would need more information about your code to answer this.
3) How do I search help or some methods/predifined variables from ruby
command prompt? Is it possible to do that? Right now the only thing I
can do is to open the folder containing the manual and read them in IE
browser. Is this the Ruby way?
There's nothing wrong with your way, but there are many other ways to get help while coding. Here are two you might consider:
2) I read each line from a file and split each of them into several
fields/segments. Then I need to populate an array with one field only
from each line. How do I do that? I know do these in Perl but have no
idea using Ruby.
Would need more information about your code to answer this.
I have a file called array.txt with many lines and each line is a record
containing different fields separated by \t. What I like to do is read
the file line by line, split each line into elements, and push the
element [1] from each line into a new array.
2) I read each line from a file and split each of them into several
fields/segments. Then I need to populate an array with one field only
from each line. How do I do that? I know do these in Perl but have no
idea using Ruby.
Would need more information about your code to answer this.
I have a file called array.txt with many lines and each line is a record containing different fields separated by \t. What I like to do is read the file line by line, split each line into elements, and push the element [1] from each line into a new array.