Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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"]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #ruby #trim #whitespace #string
ADD COMMENT
Topic
Name
4+1 =