J
Justin To
a = [["a^b^^"], ["c&def"]]
b= []
a.to_s.each_byte { |byte| (b.push(byte.chr) if !b.include?(byte.chr)) if
byte.chr.match(/\W+/) }
b.each do |c|
a=a.to_s.gsub(c, "\\#{c}").to_a
end
p a
=> ["a\\^b\\^\\^c&def"]
How come the & does not get subbed with '\\&' ??
I'm basically trying to substitute any special character with
'\\#{special_character}'
THANKS!
b= []
a.to_s.each_byte { |byte| (b.push(byte.chr) if !b.include?(byte.chr)) if
byte.chr.match(/\W+/) }
b.each do |c|
a=a.to_s.gsub(c, "\\#{c}").to_a
end
p a
=> ["a\\^b\\^\\^c&def"]
How come the & does not get subbed with '\\&' ??
I'm basically trying to substitute any special character with
'\\#{special_character}'
THANKS!