Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby trim whitespace from string

# Single string with CR/LF throughout the sting
sentence = "the quick
brown fox
jumped over
the lazy
dog"
lines.gsub(/
?/, " ")

=> "the quick brown fox jumped over the lazy dog"

# Array of strings where the CR/LF or other whitespace is at beginging or end
lines = ["    hello    ", "	goodbye
"]
lines.map(&:strip)

=> ["hello", "goodbye"]
Comment

ruby trim spaces

"   Hello  ".strip
Comment

PREVIOUS NEXT
Code Example
Ruby :: http request ruby 
Ruby :: ruby each char with index 
Ruby :: rails foreach 
Ruby :: rails string to date 
Ruby :: table name from rails console 
Ruby :: rails validate email 
Ruby :: rails crud 
Ruby :: find a key in nested hash ruby 
Ruby :: array to string ruby 
Ruby :: ruby test is number 
Ruby :: rails link to 
Ruby :: ruby map array 
Ruby :: rails generate rake task 
Ruby :: ruby latest version 
Ruby :: ruby rails where not in 
Ruby :: ruby array 
Ruby :: rails get random record 
Ruby :: grails 3 cron jobs 
Ruby :: how to remove the first element in an array ruby 
Ruby :: ruby abs function programming 
Ruby :: rails duplicate record 
Ruby :: user.destroy all except one rails 
Ruby :: ruby clear set 
Ruby :: input type checkbox checked with condition rails 
Ruby :: rails deliver_later with delay 
Ruby :: reduce ruby baud rate 
Ruby :: sequel not ruby 
Ruby :: rails list down attributes of model 
R :: r list files in directory 
R :: how to select all the records above a specific datetime in r 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =