Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to replace html tags in string using a function
WhatsApp
Ramasagar Pulidindi
10y
3.1
k
0
0
25
Blog
CREATE
FUNCTION
[dbo].[fn_parsehtml]
(
@htmldesc
varchar
(
max
)
)
returns
varchar
(
max
)
as
begin
declare
@
first
int
, @
last
int
,@len
int
set
@
first
= CHARINDEX(
'<'
,@htmldesc)
set
@
last
= CHARINDEX(
'>'
,@htmldesc,CHARINDEX(
'<'
,@htmldesc))
set
@len = (@
last
- @
first
) + 1
while @
first
> 0
AND
@
last
> 0
AND
@len > 0
begin
---Stuff function is used to insert string at given position and delete number of characters specified from original string
set
@htmldesc = STUFF(@htmldesc,@
first
,@len,
''
)
SET
@
first
= CHARINDEX(
'<'
,@htmldesc)
set
@
last
= CHARINDEX(
'>'
,@htmldesc,CHARINDEX(
'<'
,@htmldesc))
set
@len = (@
last
- @
first
) + 1
end
return
LTRIM(RTRIM(@htmldesc))
end
How to replace html tags in string using a function
Up Next
How To Backup And Replace Text In All Search String Matching Stored Procedure(S)
Ebook Download
View all
Basics of SQL Server
Read by 1.5k people
Download Now!
Learn
View all
Membership not found