Skip to content
Advertisement

Occurrence of a string inside another string

I was wondering if there is an easy way to look for a occurrence of a string inside another string. I’m using this query:

$checkfileName[0] will be set in a if-statement, where it’s set to GiM1_0. My problem is that the column doesn’t contain that specific string, only a part of it.

Image of sql table

So is there a way to “search / look” for GiM1_0 and get 'GiM10_Integrated_testbed1'. without removing the _? Maybe there is a way to see if some of the GiM1_0 is found? They both have GiM1.

Advertisement

Answer

You could remove underscores:

The ? is a parameter placeholder. I encourage you to use parameters rather than munging query strings.

The above might match a few more things than you intend.

Alternatively, you could convert to a regular expression:

The question mark makes the _ optional. This is the narrowest answer to your question.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement