Chop text after a certain symbol appears - rails -


how truncate string of text after symbol appears, such # sign? instance, want change this:

1234 ocean drive #ph 2

to:

1234 ocean drive

i've discovered apartment number in address indicated pound sign can confuse geocoder, i'd remove text appears after pound sign in self.address when telling geocoder gem address use in following situation:

property.rb

class property < activerecord::base  geocoded_by :full_address  def full_address "#{self.address}, #{self.city}, #{self.state} #{self.zip}" end 

(don't confused pound signs in above code, don't mean them, mean pound signs appear in text string self.address

str = "1234 ocean drive #ph 2" str.split('#')[0] str.slice(0..(s.index('#')-1)) str.slice(/.*#/).chop() str[/[^#]+/] 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -