java - matching two strings, one with x, other one with any characters -
java - matching two strings, one with x, other one with any characters -
i new regex not getting this. need match 2 string
s in java in 1 of them have number of x , other can have character in places.
for illustration - string 1 - time xxxx when string 2 - time 0830 when
these 2 strings should match , returns true.
please suggest.
thanks.
as many of mentioned question not clear. i'll add together more details -
1. x can appear 2 number of times. 2. strings dynamic, or in other words, they'll passed method - public boolean doesmatch(string str1, string str2) { // matching code homecoming false; }
so illustration -
this xxxday , xxxx fri ,
these 2 strings should match.
you need rebuild state engine:
public boolean doesmatch(string str1, string str2) { if (str1.length() != str2.length()) homecoming false; (int = 0; < str1.length(); i++) if (str1.charat(i) != 'x' && str1.charat(i) != str2.charat(i)) homecoming false; homecoming true; }
this loops through str1
, ensures every character in str1
, str2
equal in every position unless corresponding position @ str1
'x'
.
java regex string pattern-matching
Comments
Post a Comment