Reputation:
I have a substring what contains HTML tag and I need to shorten it but display it with the same formatting as it appears on the string.
It doesn't have to be exactly X characters long, but it should be short enough to be displayed inside a panel with a certain width and height?
Is there any way I can achieve this using c#?
What about using CSS? I.e. displaying the panel with a fixed height regardless of its content?
Thanks..
Example: I have the following panel containing a label that contains text with html tags:
I need to remove the scroll bar without making the panel longer but keeping this height & this width..
Upvotes: 2
Views: 2259
Reputation: 115
You could use a regex to find the contents of the specific tag. Use a .substring to shorten the result afterwards.
A example could be:
<h1>head</h1>
<p>contents</p>
Regex could be:
<p\b[^>]*>(.*?)</p>
Result would be:
<p>contents</p>
Now just exclude the start and end tag. as its a fixed length.
I found more interesting reading about changing the content between HTML tags. Take a read here (regex ftw!):
Another solution that might not drive you as crazy if you want to solve it in c#:
Take a look at the examples part of the site. Great little tool!
Upvotes: 2
Reputation: 5208
If you have following html code:
<div class="div1"> Some Really Bold String </div>
You can provide css to hide the scroll bars,
.div { overflow:hidden; height:200px; width:200px;}
height
and width
values are just for example purpose.
overflow:hidden
does not let the content of the div to expand out side the div.
you will find more information on overflow
here.
Upvotes: 2