Subashini Kumar
2010-Jan-06 08:35 UTC
html formatted string & displaying only upto specific length
Hi I have a string str="<p>H<span style="font-family: impact,chicago;">g</span>enrik Lundqvist,g<span style="font-family: georgia,palatino;">gh nv <span style="font-family: wingdings,zapf dingbats;">gnm h fsgfb g</span></span>the preternaturally handsome Swedish goalie for the New York Rangers, may have been named one of test from Neskdufluh on december <span style="font-family: symbol;">a</span> 2009</p>" i want to display this with the html formatting as mentioned above in the string. But i want to display only first 15 charatcer.ie 15 characters inclusive of spaces and other special charac that is , i want to display HgenrikLundqvis . But it should be display with all the html formatting as it is in the string "str". please tell me how to display it like this. -- Posted via http://www.ruby-forum.com/. -- 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.
Matt Jones
2010-Jan-07 15:47 UTC
Re: html formatted string & displaying only upto specific length
On Jan 6, 3:35 am, Subashini Kumar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > > I have a string > > str="<p>H<span style="font-family: impact,chicago;">g</span>enrik > Lundqvist,g<span style="font-family: georgia,palatino;">gh nv <span > style="font-family: wingdings,zapf dingbats;">gnm h fsgfb > g</span></span>the preternaturally handsome Swedish goalie for the New > York Rangers, may have been named one of test from Neskdufluh on > december <span style="font-family: symbol;">a</span> 2009</p>" > > i want to display this with the html formatting as mentioned above in > the string. > But i want to display only first 15 charatcer.ie 15 characters inclusive > of spaces and other special charac > that is , i want to display HgenrikLundqvis . > But it should be display with all the html formatting as it is in the > string "str". > please tell me how to display it like this.I don''t think what you''re looking for is even possible in general: you''d need to first parse the entire HTML string, find "15 characters" and then put the formatting back on. That''s not even including the possibility of devious stuff like this: A string with <span style="display:none">hidden bits</span>. The first 15 *visible* characters here are "A string with .", but unless you''re parsing the CSS as well, you''d end up producing "A string with h". Finally, fixed character truncation can be tricky; does the client *really* want to see "Foo Bar Baz Association" truncated to 15 characters? :) --Matt Jones -- 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.