I’ve been using the match function in Processing to match strings. I am however experiencing problems when trying to match strings from within an array of strings. The code below is an example of what I am trying to do:
String zj = "(V)X(PL)X(FR)";
String z = "(V)X(AV)X(FR2)";
String[] list4 = split (zj,'X');
String[] list5 = split (z, 'X');
String BZJ = list4[0];
String BZ = list5[0];
String [] Y = match (BZJ,BZ);
if (Y != null)
{
println ("correct");
}
else
{
println ("incorrect");
}
The problem is I only ever recieve an answer of ‘incorrect’ if ALL of the characters are different. From the printout it seems that the function is satisfied if it can match ANY character. So for the example code, my program would match “FR” with “FR2”. If I alter the strings artificially to make them different in every single character, then (and only then) I receive an answer of ‘incorrect’. This is not the case if I simply compare two strings independently, where the function (as far as I can tell) is only satisfied if the entire string matches. Any ideas greatly appreciated as always.
In your example code, simply using
.equals()will work: