Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
(1) I am getting some text from database like this
<div> Demo Patient </div> 

I want to remove div tag from starting and ending to get it as
Demo Patient
. How can I do that ?

(2) My second questions is that I have to show my data as tooltipe like this
Patient Name: David,
Address : United States

How can I arrange this using tr or div and show as tool tip in javascript.

Please guide
Posted
Comments
The Doer 27-Apr-12 4:38am    
Use substring function to get the "demo Patient "..
(2) is not clear to me..

solution for first question

what ever the html tag it is, it will be removed from the string using this function

take this
<div> Demo Patient </div>
in one string variable like this

string name="<div> Demo Patient </div>";



//add this function in your page

public string StripTagsCharArray(string source)
       {
           char[] array = new char[source.Length];
           int arrayIndex = 0;
           bool inside = false;

           for (int i = 0; i &lt; source.Length; i++)
           {
               char let = source[i];
               if (let == '&lt;')
               {
                   inside = true;
                   continue;
               }
               if (let == '&gt;')
               {
                   inside = false;
                   continue;
               }
               if (!inside)
               {
                   array[arrayIndex] = let;
                   arrayIndex++;
               }
           }
           string data = new string(array, 0, arrayIndex);

           return data;
       }



//call the function like this

name=StripTagsCharArray(name);




and finally
output is :Demo Patient
 
Share this answer
 
v2
Comments
member60 25-Oct-12 7:39am    
My 5!
Answer to your second question:

//Javascript:

XML
<script type="text/javascript" language="javascript">
function showToolTip(e, text)
        {
            document.all.ToolTip.innerHTML = "<table><tr><td class=ToolTipTD>" + text + "</td></tr></table>";
            ToolTip.style.pixelLeft = (e.x + 15 + document.body.scrollLeft);
            ToolTip.style.pixelTop = (e.y + document.body.scrollTop);
            ToolTip.style.visibility = "visible";
        }
        function hideToolTip() {
            ToolTip.style.visibility = "hidden";
        }
</script>



//Look n feel for tool tip

XML
<style>
#ToolTip{position:absolute; top:0; left:0; right: auto;background:#fffedf;border-color:#000;border-style:solid;border-width:1px 1px 1px 1px;visibility:hidden; padding: 10px;}
.ToolTipTD {color:black; font-size: 10px;}
</style>



call the javascript function on mousehover wherever you want. For eg on row tag:
< tr onmouseover="javascript:showToolTip(event,"Put your data here.")" önmouseout="javascript:hideToolTip()"


Thanks,
Deepti
 
Share this answer
 
v2
Ans 1) Use below function to strip HTML tag from your text.
SQL
CREATE FUNCTION [dbo].[udf_StripHTML]
(@HTMLText VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Start INT
DECLARE @End INT
DECLARE @Length INT
SET @Start = CHARINDEX('<',@HTMLText)
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
WHILE @Start > 0
AND @End > 0
AND @Length > 0
BEGIN
SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
SET @Start = CHARINDEX('<',@HTMLText)
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
END
RETURN LTRIM(RTRIM(@HTMLText))
END


Call function like this :
SQL
SELECT dbo.udf_StripHTML('TEST<br><br><a href="http://yoursite.com">yoursite.com</a>')
</br></br>


ans 2) Use overlib [^] or try jQuery plugins.
 
Share this answer
 
1)One way is to use string functions(depends on how your string is).
string.Replace("<div>","");</div> or indexof[^]
2)javascript tooltip[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900