C# Screw (2/9/2010)
Thanks Jeffyour PATINDEX idea seems a step closer to a dream 'WildReplace' function which might be :
CREATE FUNCTION dbo.fn_WildReplace(@SomeText varchar(max),
@Pattern varchar(500), @ReplaceWith varchar(max))
.....
Edit: corrected syntax
Usage :
SELECT dbo.fn_WildReplace('Without a doubt SQLCentral is
home to finest SQL folk[comment:#grovel].', '%[comment:#%]', '')
--returning:
--Without a doubt SQLCentral is home to finest SQL folk.
The function doesn't specify any start or end markers, just a pattern to find and replace.
I can see we can use PATINDEX to find start location of the pattern, but I canny figure out how you would determine the end location of the pattern?
It's easy if you want to do that. Just do a split on the % in a single pattern to replace the left and right patterns. I was just being a bit lazy... didn't want to have to worry about writing code to escape the % if someone needed to look for it.
--Jeff Moden
Change is inevitable... Change for the better is not.