Replace comma with space

Hi,

Can anyone help me? I have strings like, 1,2,A and 4, 5, B. When I
insert into the table, I want it to be like this:

id my_string
1 1 2 A
2 4 5 B

instead of

id my_string
1 1,2,A
2 4, 5, B

How can I achieve that? I have read some where that I could use
replace(). But I still don't know how to use it. Is there a better way?
If not how do I use replace() ?

Thanks

user splash wrote:

How can I achieve that? I have read some where that I could use
replace(). But I still don't know how to use it. Is there a better way?
If not how do I use replace() ?

Hi,

I have found gsub() example. It works in the console but it doesn't work
in the controller. Des anyone knows why?

Thanks

I use the following

NEW_DATA = OLD_DATA.gsub(/\s*,\s*/, ',')
or
YOUR_DATA.gsub!(/\s*,\s*/, ',')

So that it takes care of variations like this:
    1, 2,3 , 4

You can even do something like:
"1,2,A".split(",").join(" ")

Not sure which one is the fastest though.

Greg Willits wrote:

I use the following

NEW_DATA = OLD_DATA.gsub(/\s*,\s*/, ',')
or
YOUR_DATA.gsub!(/\s*,\s*/, ',')

So that it takes care of variations like this:
   1, 2,3 , 4

Love AJAX wrote:

You can even do something like:
"1,2,A".split(",").join(" ")

Not sure which one is the fastest though.

Thanks guys. Problem solved :smiley: