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

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -