Reputation: 708
I want to find & remove a string from string. See the examples below,
Input1:
a = 'mangalore'
Input2
b = 'mc'
Outputs
b values should not present in a for output1 #angalore
a values should not present in b for output2 #c
Solutions: converting string a,b to array then doing a-b & b-a
it will give results. How to implement using string in ruby.
Helps appreciated!
Upvotes: 0
Views: 59
Reputation: 121000
Use String#tr
:
main > 'mangalore'.tr 'mc', '#'
#⇒ "#angalore"
main > 'mc'.tr 'mangalore', '#'
#⇒ "#c"
Upvotes: 3