Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace String

Status
Not open for further replies.

jayfox

Programmer
Joined
Dec 19, 2002
Messages
29
Location
US
I have a text field with html tags in it and I want to get rid of them. I would like to replace everything between'<' and '>'. There will be more than one occurance od this in the field.
Please help.
 
so if the field contains '123<some text>456' you want to remove all between the < and > to leave '123<>456' or leave '123456' or do you just want to remove the < and > to leave '123some text456'

If it is the latter do you want spaces where the < and > where ?

DBomrrsm
 
I would like also to remove < and >
 
SELECT REPLACE(MYField,'<',' ')
Go
SELECT REPLACE(MYField,'>',' ')
Go

DBomrrsm

 
You want to strip out HTML tags... maybe it isn't good idea to do it in database but anyway - try this:
Code:
create function strip_tags( @s varchar(4000) )
returns varchar(4000) as
begin
	declare @pos1 smallint, @pos2 smallint
	set @pos2 = 1

	while @pos2  > 0
	begin
		set @pos1 = charindex('<', @s, @pos2)
		set @pos2 = charindex('>', @s, @pos1+1)
		if @pos1 = 0 or @pos2 = 0 break

		set @s = left(@s, @pos1-1) + right(@s, len(@s)-@pos2)
		set @pos2 = @pos2-2
	end

	return @s
end
Bugs included, comments welcomed :X
 
Just looking at this it will not remove the text in between < and >.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top