A wordfilter (sometimes referred to as just "filter" or "censor") is a script typically used on Internet forums or chat rooms that automatically scans users' posts or comments as they are submitted and automatically changes or censors particular words or phrases.
The SQL replace Function
is use to replace a string.to filter bad word in a sentence ,first create a
table and insert a list of words to be replaced…
Example: Create Query:
CREATE TABLE
[dbo].[FILTERWORD](
[string] [nvarchar](100) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL,
[replacement] [nvarchar](100) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL
)
Result Table:
SQL Function for
filtering a particular word in a
sentence:
Create FUNCTION [dbo].[filter](@word varchar(max))
RETURNS varchar(50)
AS
BEGIN
declare @cnt
varchar(MAX)
SELECT @cnt = REPLACE(@words,string,replacement)
FROM FILTERWORD;
return @cnt;
END
Execution Query:
declare @word varchar(50)
set @word='he is a stupid boy'
select dbo.filter(@word)
Result: