ruby 1.8.6 (2007-09-24 patchlevel 111) str = ''\&123'' puts "abc".gsub("b", str) puts "abc".gsub("b", "#{str}") puts "abc".gsub("b", str.to_s) puts "abc".gsub("b", ''\&123'') puts "abc".gsub("b", "\&123")>ruby test.rbab123c ab123c ab123c ab123c a&123c <------------------- This I want to achieve using temporary variable>Exit code: 0If I change str = ''\&123'' to str = "\&123" it works fine, but I get str from "match" function, so I cannot specify it manually within parantheses.... Is there any way to change string''s ''string'' to "string" behaviour??? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The exact problem a = ''<template><aaa:bbb/></template>'' b = ''<a class="add_line" href="#" id="add_fields_invoice_lines" onclick="add_fields(this, "invoice_lines", "<fieldset class\"inputs invoice_line\"><ol>\n <li class\"string required invoice_line_name\" id=\""'' str = (b.match /.*/)[0] puts str pn="bbb" puts a.gsub("<aaa:#{pn}\/>", str) => <template><a class="add_line" href="#" id="add_fields_invoice_lines" onclick="add_fields(this, "invoice_lines", "<fieldset class=<aaa:bbb/>quot;inputs invoice_line<aaa:bbb/>quot;><ol>\n <li class=<aaa:bbb/>quot;string required invoice_line_name<aaa:bbb/>quot; id=<aaa:bbb/ >quot;"</template>On 19 Lut, 09:47, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ruby 1.8.6 (2007-09-24 patchlevel 111) > > str = ''\&123'' > puts "abc".gsub("b", str) > puts "abc".gsub("b", "#{str}") > puts "abc".gsub("b", str.to_s) > puts "abc".gsub("b", ''\&123'') > puts "abc".gsub("b", "\&123") > > >ruby test.rb > > ab123c > ab123c > ab123c > ab123c > a&123c <------------------- This I want to achieve using temporary > variable > > >Exit code: 0 > > If I change > str = ''\&123'' > to > str = "\&123" > it works fine, but I get str from "match" function, so I cannot > specify it manually within parantheses.... Is there any way to change > string''s ''string'' to "string" behaviour???-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Not sure I understand. From a&123c <------------------- This I want to achieve using temporary I ask, do you know that & does not need escaping? "abc".gsub("b", "&123") # => "a&123c" -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 19, 8:47 am, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ruby 1.8.6 (2007-09-24 patchlevel 111) > > str = ''\&123'' > puts "abc".gsub("b", str) > puts "abc".gsub("b", "#{str}") > puts "abc".gsub("b", str.to_s) > puts "abc".gsub("b", ''\&123'') > puts "abc".gsub("b", "\&123")Why are you escaping the & at all ? str = ''&123'' puts "abc".gsub("b", str) outputs a&123c for me Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It was received from already escaped html mixed with javascript - that is why :( I have no influence on the fact that these slashes are there... Anyway I have came up with a solution - maybe there is a simpler way, however the code below works str = ''\&123'' puts "abc".gsub("b", str.gsub(/\&/o, ''\\\&\2\1'')) => a\&123c On 19 Lut, 11:27, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 19, 8:47 am, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ruby 1.8.6 (2007-09-24 patchlevel 111) > > > str = ''\&123'' > > puts "abc".gsub("b", str) > > puts "abc".gsub("b", "#{str}") > > puts "abc".gsub("b", str.to_s) > > puts "abc".gsub("b", ''\&123'') > > puts "abc".gsub("b", "\&123") > > Why are you escaping the & at all ? > > str = ''&123'' > puts "abc".gsub("b", str) > > outputs a&123c for me > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Argh - slashes missing -> here is the pastie code -> http://pastie.org/832493 On 19 Lut, 11:46, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It was received from already escaped html mixed with javascript - that > is why :( > I have no influence on the fact that these slashes are there... > > Anyway I have came up with a solution - maybe there is a simpler way, > however the code below works > > str = ''\&123'' > > puts "abc".gsub("b", str.gsub(/\&/o, ''\\\&\2\1'')) > > => a\&123c > > On 19 Lut, 11:27, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Feb 19, 8:47 am, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > ruby 1.8.6 (2007-09-24 patchlevel 111) > > > > str = ''\&123'' > > > puts "abc".gsub("b", str) > > > puts "abc".gsub("b", "#{str}") > > > puts "abc".gsub("b", str.to_s) > > > puts "abc".gsub("b", ''\&123'') > > > puts "abc".gsub("b", "\&123") > > > Why are you escaping the & at all ? > > > str = ''&123'' > > puts "abc".gsub("b", str) > > > outputs a&123c for me > > > Fred > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Feb 19, 2010 at 11:48 AM, stevo84 <blazejek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Argh - slashes missing -> here is the pastie code -> http://pastie.org/832493Easier: "abc".gsub("b") { |_| str } There str is taken verbatim. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 19, 2010, at 5:14 AM, stevo84 wrote:> The exact problem > > a = ''<template><aaa:bbb/></template>'' > b = ''<a class="add_line" href="#" id="add_fields_invoice_lines" > onclick="add_fields(this, "invoice_lines", "<fieldset class> \"inputs invoice_line\"><ol>\n <li class> \"string required invoice_line_name\" id=\""'' > > str = (b.match /.*/)[0] > > puts str > > pn="bbb" > > puts a.gsub("<aaa:#{pn}\/>", str)So did you try: a.gsub("<aaa:#{pn}\/>") { b } -Rob> > => <template><a class="add_line" href="#" > id="add_fields_invoice_lines" onclick="add_fields(this, > "invoice_lines", "<fieldset class=<aaa:bbb/>quot;inputs > invoice_line<aaa:bbb/>quot;><ol>\n <li class=<aaa:bbb/ >> quot;string required invoice_line_name<aaa:bbb/>quot; id=<aaa:bbb/ >> quot;"</template> > > On 19 Lut, 09:47, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> ruby 1.8.6 (2007-09-24 patchlevel 111) >> >> str = ''\&123'' >> puts "abc".gsub("b", str) >> puts "abc".gsub("b", "#{str}") >> puts "abc".gsub("b", str.to_s) >> puts "abc".gsub("b", ''\&123'') >> puts "abc".gsub("b", "\&123") >> >>> ruby test.rb >> >> ab123c >> ab123c >> ab123c >> ab123c >> a&123c <------------------- This I want to achieve using temporary >> variable >> >>> Exit code: 0 >> >> If I change >> str = ''\&123'' >> to >> str = "\&123" >> it works fine, but I get str from "match" function, so I cannot >> specify it manually within parantheses.... Is there any way to change >> string''s ''string'' to "string" behaviour??? > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No, I did not... and it sure works! I knew that it should be easier :) Thank You for another piece of knowledge, Rob and Xavier On 19 Lut, 16:08, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Feb 19, 2010, at 5:14 AM, stevo84 wrote: > > > The exact problem > > > a = ''<template><aaa:bbb/></template>'' > > b = ''<a class="add_line" href="#" id="add_fields_invoice_lines" > > onclick="add_fields(this, "invoice_lines", "<fieldset class> > \"inputs invoice_line\"><ol>\n <li class> > \"string required invoice_line_name\" id=\""'' > > > str = (b.match /.*/)[0] > > > puts str > > > pn="bbb" > > > puts a.gsub("<aaa:#{pn}\/>", str) > > So did you try: > a.gsub("<aaa:#{pn}\/>") { b } > > -Rob > > > > > > > => <template><a class="add_line" href="#" > > id="add_fields_invoice_lines" onclick="add_fields(this, > > "invoice_lines", "<fieldset class=<aaa:bbb/>quot;inputs > > invoice_line<aaa:bbb/>quot;><ol>\n <li class=<aaa:bbb/ > >> quot;string required invoice_line_name<aaa:bbb/>quot; id=<aaa:bbb/ > >> quot;"</template> > > > On 19 Lut, 09:47, stevo84 <blaze...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> ruby 1.8.6 (2007-09-24 patchlevel 111) > > >> str = ''\&123'' > >> puts "abc".gsub("b", str) > >> puts "abc".gsub("b", "#{str}") > >> puts "abc".gsub("b", str.to_s) > >> puts "abc".gsub("b", ''\&123'') > >> puts "abc".gsub("b", "\&123") > > >>> ruby test.rb > > >> ab123c > >> ab123c > >> ab123c > >> ab123c > >> a&123c <------------------- This I want to achieve using temporary > >> variable > > >>> Exit code: 0 > > >> If I change > >> str = ''\&123'' > >> to > >> str = "\&123" > >> it works fine, but I get str from "match" function, so I cannot > >> specify it manually within parantheses.... Is there any way to change > >> string''s ''string'' to "string" behaviour??? > > > -- > > You received this message because you are subscribed to the Google > > Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails- > > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > . > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > > . > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.