List:General Discussion« Previous MessageNext Message »
From:Jim Lyons Date:October 24 2008 10:37pm
Subject:Re: How to count # of character occurrences in a string?
View as plain text  
 A quick and dirty way would be to use an expression like

length(x) - length(replace(x, ":", ""))

Here's some code that I actually ran:

set @x = "aa:bb:cc:dd";
set @colons = length(@x) - length(replace(@x, ":", ""));
select @x ,  @colons;


On Fri, Oct 24, 2008 at 5:16 PM, mos <mos99@stripped> wrote:

> I have a Char column with text data like "ab:cdef:h" and I'd like to count
> the number of ":" in the column. I can't find an easy way to do it. I
> thought there should be a MySQL function to do this. Any suggestions?
>
> TIA
> Mike
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
>


-- 
Jim Lyons
Web developer / Database administrator
http://www.weblyons.com

Thread
How to count # of character occurrences in a string?mos25 Oct
  • Re: How to count # of character occurrences in a string?Pintér Tibor25 Oct
  • Re: How to count # of character occurrences in a string?Jim Lyons25 Oct