html formatted string -displaying only upto specific length

  • Thread starter Subashini Kumar
  • Start date
S

Subashini Kumar

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.
 
M

Marnen Laibow-Koser

Subashini said:
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.

You'll need to parse the HTML to know where the tags begin and end. Use
a library such as Nokogiri for that.

You could do a quick-and-dirty approach using regular expressions, but
it may not be as reliable.

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top