Wildcard in IF statement

I am trying to pull in a directory of sound files using listDir. I am using dir.getName to do an IF statement, but want to use a wildcard in the filename to find the file with a preceeding 1 in the filename, regardless of the rest.

I.E.

if(dir.getName(i) == “1*”){
snd1.loadSound(dir.getPath(i));

This does not work, and i have scoured around quite a bit to find a way to do a regular expression, etc, in this way.

Any ideas?

I think i found the solution, i need to use substr…

for(int i = 0; i < (int)dir.size(); i++){

string str = dir.getName(i);

if(str.substr (0,1) == “1”) {
snd1.loadSound(dir.getPath(i));

Using substr is better (faster, but not really material), but wildcard matching is called ‘globbing’ and a google search for ‘globbing c++’ shows up some stuff that might be of interest for you

Thanks, i’ll look into it.

Have an additional question, is it possible to pass the substr results as a variable to say, ofSoundPlayer and loudSound functions?

like:

ofSoundPlayer str.substr (0,1);
str.substr (0,1).loadSound(dir.getPath(i));

of course the above doesnt work, but curious if there is a way to pass the value and/or data that the substr represents? It appears that the ofSoundPlayer and loadSound doesnt like referencing a string…

Not really for what it sounds like you want to do.

If you know you will have a number of sounds, you can store them in an array of OfSoundPlayer objects. Or you could use a Map type of <string, ofSoundPlayer> http://en.wikipedia.org/wiki/Associative-containers-(C%2B%2B