Posted By

almazom on 02/17/10


Tagged

ruby trim String


Versions (?)

replace quotes & trim (left and right)


 / Published in: Rails
 

  1. def remove_q_n_trim str
  2. return str.gsub(/"|^ +| $+|\n/i,'').to_s
  3. end

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: TomL on February 17, 2010

I tried it with the string " \" hello " and it didn't remove the two spaces before the "h".

How about: def removequotesand_spaces(str) str.gsub("\"","").strip end

Posted By: TomL on February 17, 2010

I tried it with the string " \" hello " and it didn't remove the two spaces before the "h".

How about: def removequotesand_spaces(str) str.gsub("\"","").strip end

Posted By: almazom on February 24, 2010

def removeqntrim str return str.gsub(/"|^ | $|\n/i,'').tos end

added new line removing

Posted By: almazom on February 24, 2010

def removeqntrim str return str.gsub(/"|^ +| $+|\n/i,'').tos end

to TOM:

now it must remove 2 and more spaces in the left and right of the string (added '+')

You need to login to post a comment.