-2
public void searchSong(String songToSearch){
    Toast.makeText(getApplicationContext(), songToSearch, Toast.LENGTH_SHORT).show();
    boolean found = false;
    for(int i = 0; i < fileArray.length; i++ ){
        String value = fileArray[i].toLowerCase().replace(".mp3","");
        if (songToSearch.toLowerCase().matches(value) && !found) {
            Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
            found = true;
        } else {
            found = false;
        }
        if(found){
            Toast.makeText(getApplicationContext(), "Found", Toast.LENGTH_SHORT).show();
        }
    }
}

I want to use the code to check if the songToSearch is a part of any string inside the fileArray Example lets say that fileArray[2] is equal to "Hello world" and the songToSearch is equal to "world" I would like to make the boolean found true... However this is not happening... the boolean never changes

2 Answers2

0

see docs: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html

public boolean  matches(String regex)

Tells whether or not this string matches the given regular expression.

you need:

public boolean contains(CharSequence s)
LunaVulpo
  • 3,043
  • 5
  • 30
  • 58
0
            if (Pattern.compile(Pattern.quote(songToSearch), Pattern.CASE_INSENSITIVE).matcher(value).find()) {
            playMusic(songToSearch);
        }

Would solve the problem... My post was actually a duplicate