R
Roberto Rivera
Hello,
Im working on a small rails app that uses a text editor component
(FCKEdit). In certain cases, the editor will add characters to my string
that I need to remove before I show the output.
For example, it will add '\' in front of any '"' or '\' in my document.
I was checking out String.replace and String.gsub, but they both seem to
replace any element that matches the input string.
"hello".gsub(/[aeiou]/, '*') #=> "h*ll*"
In my particular case, I need it to match the whole string for
substitution.
I worked out this code in order to substitute '\"' for '"' and '\\' for
'\':
<%= text.split('\"').join('"').split("\\\\").join("\\") %>
Im sure there's gotta be some other way to make it work without breaking
it into arrays and rejoining.
Any help will be appreciated.
az
Im working on a small rails app that uses a text editor component
(FCKEdit). In certain cases, the editor will add characters to my string
that I need to remove before I show the output.
For example, it will add '\' in front of any '"' or '\' in my document.
I was checking out String.replace and String.gsub, but they both seem to
replace any element that matches the input string.
"hello".gsub(/[aeiou]/, '*') #=> "h*ll*"
In my particular case, I need it to match the whole string for
substitution.
I worked out this code in order to substitute '\"' for '"' and '\\' for
'\':
<%= text.split('\"').join('"').split("\\\\").join("\\") %>
Im sure there's gotta be some other way to make it work without breaking
it into arrays and rejoining.
Any help will be appreciated.
az