Neeraj Kumar
2007-Jan-08 17:52 UTC
How to add to string a large text with single and double quotes
I''m sure there must be an easier way to add a large text to a string
variable than doing
temp_string = ''''a very large text"
For example my text is:
var badge = '''';
badge += ''<div class="upb_date"><span
class="upb_text">Jan
8</span></div>'';
badge += ''<div class="upb_event"
id="upcoming_badge_1"><span
class="upb_title upb_text"><a
href="http://upcoming.org/event/80128/">COMSWARE 2007 HE SECOND
IEEE/Create-Net/...</a></span>'';
badge += '' <span class="upb_venue upb_text">@ <a
href="http://upcoming.org/venue/25891/">NOT YET
DECIDED</a></span>'';
badge += ''</div>'';
document.write(badge);
I want all that in a variable @badge_text. How do I do that easily?
Thanks
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@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
-~----------~----~----~----~------~----~------~--~---
Bart
2007-Jan-08 20:04 UTC
Re: How to add to string a large text with single and double quotes
You can use straight Ruby for this. String has a "here" document.
Itworks liek this:
badge = <<MY_TEXT_END
<div class="upb_date"><span
class="upb_text">Jan 8</span></div>
<div class="upb_event" id="upcoming_badge_1">
<span class="upb_title upb_text">
<a href="http://upcoming.org/event/80128/">
COMSWARE 2007 HE SECOND IEEE/Create-Net/...
</a>
</span>
<span class="upb_venue upb_text">@
<a href="http://upcoming.org/venue/25891/">
NOT YET DECIDED
</a>
</span>
</div>
MY_TEXT_END
badge now has all of this, with all single and double qoutes escaped
with a ''\'' character. Note that new lines are preserved in
the string
as ''\n''.
For all other info, check out "String" in
http://ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html
Bart
Neeraj Kumar wrote:> I''m sure there must be an easier way to add a large text to a
string
> variable than doing
>
> temp_string = ''''a very large text"
>
> For example my text is:
>
> var badge = '''';
> badge += ''<div class="upb_date"><span
class="upb_text">Jan
> 8</span></div>'';
> badge += ''<div class="upb_event"
id="upcoming_badge_1"><span
> class="upb_title upb_text"><a
> href="http://upcoming.org/event/80128/">COMSWARE 2007 HE
SECOND
> IEEE/Create-Net/...</a></span>'';
> badge += '' <span class="upb_venue upb_text">@
<a
> href="http://upcoming.org/venue/25891/">NOT YET
DECIDED</a></span>'';
> badge += ''</div>'';
> document.write(badge);
>
>
> I want all that in a variable @badge_text. How do I do that easily?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@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
-~----------~----~----~----~------~----~------~--~---