Solved

Need MySQL string function

Posted on 2011-09-13
3
455 Views
Last Modified: 2012-05-12
Experts,

new to mySQL.

i'm using the following function on a string in vb.net:

 Public Function subStringCount(ByVal fullString As String, ByVal subString As String) As Integer
       
        Dim r As New Regex(subString)
        Dim mc As MatchCollection = r.Matches(fullString)

        Return mc.Count

    End Function

i'm calling it like this:

    subStringCount(strGameHistory, "ET")

It takes a string and counts the occurance of a subset of characters within the string.

my data can look like this: "S0ETS2ETS5C0ETS2C0ETS1C1ET"

Is it possible to have this operation done within the where clause of my select? I'd rather not have to pull all the data back before performing this operation. so, something like:

select game_history from table1 where function_counting_occurance_subset_of_char(game_history, 'ET') = 5;

TIA,

crafuse
 
0
Comment
Question by:crafuse
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 36534021
I think this technique should kind of work, but it's a little hacky:
http://pisceansheart.wordpress.com/2008/04/15/count-occurrence-of-character-in-a-string-using-mysql/

Which would give this I believe:
select game_history from table1 where ( (LENGTH(game_history) - LENGTH(REPLACE(game_history, 'ET', '')))/LENGTH('ET') ) = 5;
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36534042
Having a bit more of a look around the web, it appears that's the best way to do it.
0
 

Author Closing Comment

by:crafuse
ID: 36534064
this is a perfect example of why this site can be pretty amazing!

great answer, works like a charm, thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now