//////////////// Sql String
///////////////////// Result
Total Count of 't' : 4, Total Count of 'h' : 1, Total Count of 'i' : 3, Total Count of 's' : 4, Total Count of ' ' : 4, Total Count of 'a' : 1, Total Count of 'e' : 1, Total Count of 'r' : 1, Total Count of 'n' : 1, Total Count of 'g' : 1,
declare @str varchar(max)='this is a test string', @tlen int=0,@lstStr varchar(max)='',@fStr varchar(max)='',@Fchar varchar(10)=''
set @tlen=len(@str)
while @tlen>0
begin
set @Fchar=left(@str,1)
set @fStr=@fStr+'Total Count of '''+@Fchar+''' : '+cast(len(@str)-len(replace(@str,@Fchar,'')) as varchar)+', '
set @str=replace(@str,@Fchar,'')
set @tlen=len(@str)
end
print @fStr
///////////////////// Result
Total Count of 't' : 4, Total Count of 'h' : 1, Total Count of 'i' : 3, Total Count of 's' : 4, Total Count of ' ' : 4, Total Count of 'a' : 1, Total Count of 'e' : 1, Total Count of 'r' : 1, Total Count of 'n' : 1, Total Count of 'g' : 1,
No comments:
Post a Comment