سؤال

I have the following string:

"test,Hello, Inc.,test2"

I want this to read:

"test,Hello Inc.,test2"

Essentially I want to convert all "Hello, Inc." to "Hello Inc.". All commas should be removed from that string only.

I am using ruby 2.0.0 and rails 4.0.0. How can I do that?

هل كانت مفيدة؟

المحلول 2

This should work for you specific example.

"test,Hello, Inc.,test2".gsub(/Hello, Inc\./,"Hello Inc.")

نصائح أخرى

my_string, x = "test,Hello, Inc.,test2", 'Hello, Inc'

my_string[x] = x.delete(',')

p my_string #=> "test,Hello Inc.,test2"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top