[ ruby on rails ] String sub and remove

remove

all occurrences of the patterns removed

"foo bar test test test".remove(" test") # "foo bar"

 

sub

first occurrence of pattern substituted for the second argument

Example

"hello".sub(/[aeiou]/, '*') #=> "h*llo"

ref : https://apidock.com/ruby/String/sub,

https://apidock.com/rails/String/remove

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s