ruby remove crlf

106

# Single string with CR/LF throughout the sting
sentence = "the quick\r\nbrown fox\r\njumped over\r\nthe lazy\r\ndog"
lines.gsub(/\r\n?/, " ")

=> "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    ", "\tgoodbye\r\n"]
lines.map(&:strip)

=> ["hello", "goodbye"]

Comments

Submit
0 Comments

More Questions

rails migration update column default valuerails remove model ruby get current datetime
Your Ruby version is 3.0.0, but your Gemfile specified 2.7.4rails kill server iterate over string ruby
ruby hash mergehow to I change the name of a column in rails how to remove columns from rails
contains ruby arrayruby is int ruby each do method
ruby iterate over arrayruby array has element drop rails all db
destroy existed porthow to check ruby version kill puma pid local
kill port already in useif contains ruby rails remove column from model
rails image tagAdd references rails migration how to delete a table in rails
if the version you need is missing, try upgrading ruby-build.error: while executing gem ... (gem::filepermissionerror) how to convert a string to lower or upper case in ruby
find records created in a particular month railsdb migration rollback specific migration rails how to get associations from a model in rails
how to select first n data in an array rubyruby glob all nested file except directories destroy parent when you destroy child rails
how to turn string array to int array rubyruby iterate over each character in string rails api only with postgress and rspec
rails api active storage get image urlcreate rails app in current directory rails validate no special characters
ruby refinement import dynamic methodsread file in ruby with relative path how to see rails routes in browser
rails model validate integer rangeruby struct with keyword arguments ruby remove unsafe file characters
ruby extract filename from pathgenerate controller for devise rails engine table doesnt exist