I have an issue with a string compare problem…
lets say: string a = “0123456789ABCDEF” string b = “00CC0G”
how do i loop a java code so i can check string a for match with each letter from string b. While comparing the match, the letter from string b has to go thru the entire loop against string a before deciding if there is a match or not. if a match is found it should check the next letter in string b against string a and so on until the last letter in string b. if no match is found, the function shud exit the loop and return false. otherwise if each letter in string b is a match atleast once with string a, the function shud return true.
Example… the function should return false, because the first 5 letters match but the last one doesnt.
any idea? Thanks
EDIT: what i have so far
public boolean checkVal(String b) {
// b = "00CC0G";
String a = "0123456789ABCDEF";
String toUC = b.toUpperCase();
char[] cArray = toUC.toCharArray();
char[] vArray = a.toCharArray();
int j = 0;
int m = 0;
for (int i = 0; i <=cArray.length(); i++) {
for (int k = 0; k <= vArray.length(); k++) {
if (cArray[k] == vArray[i]) {
j++;
}
else {
m--;
break; //loop should exit if there is a non match and function should return false
}
}
}
if (j > 0) return true; //string a matched atleast once with string b
if (m < 0) return false; //string a alteast has one NO MATCH with string b
}
The looping is what getting me confused…
Spoonfeeding since 2k12.