October 1, 2007 at 9:38 am
Comments posted to this topic are about the item Counting ocurrences in a string
October 2, 2010 at 10:25 am
I modified your code to make it more useful.
DECLARE @s-2 NVARCHAR(MAX)
DECLARE @result INT
DECLARE @count_me NVARCHAR(MAX)
/*
The string to be searched.
*/
SET @s-2 = '1101001001110101'
/*
The character to be counted.
*/
SET @count_me = '00'
/*
Replace the character to be counted with empty string,
and subtract the lengths.
*/
SET @result = (LEN(@s) - LEN(REPLACE(@s,@count_me,'')) )/LEN(@count_me)
/*
Do something with the result
*/
PRINT @result
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy