Send this to a friend
1 def trim_by_words(string,wordcount)
2 string.split[0..(wordcount-1)].join(" ") +(string.split.size > wordcount ? "..." : "")
3 end
4
5
6 string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
7
8 puts trim_by_words(string,10)
def trim_by_words(string,wordcount)
string.split[0..(wordcount-1)].join(" ") +(string.split.size > wordcount ? "..." : "")
end
string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
puts trim_by_words(string,10)
Send this to a friend
1 test = "hello man! how are you?"
2 puts test.split(/\s+/).each{ |word| word.capitalize! }.join(' ')
test = "hello man! how are you?"
puts test.split(/\s+/).each{ |word| word.capitalize! }.join(' ')
Send this to a friend
1 def get_file_as_string(filename)
2 data = ''
3 f = File.open(filename, "r")
4 f.each_line do |line|
5 data += line
6 end
7 return data
8 end
9
10 test = get_file_as_string 'myfile.txt'
11 puts test
def get_file_as_string(filename)
data = ''
f = File.open(filename, "r")
f.each_line do |line|
data += line
end
return data
end
test = get_file_as_string 'myfile.txt'
puts test
Send this to a friend
1
2
3 myString = "Paris in Spring"
4 myString.insert 8, " the"
5
6
7
8 myString = "Only a test!!!"
9 myString.gsub(/[^a-zA-Z|\s]/,'')
10
11
12
13 myString = "I love ASP"
14 myString.gsub('ASP','Ruby')
myString = "Paris in Spring"
myString.insert 8, " the"
myString = "Only a test!!!"
myString.gsub(/[^a-zA-Z|\s]/,'')
myString = "I love ASP"
myString.gsub('ASP','Ruby')