, you need to do a fuzzy match of the string in Java, because the object length to compare, there is no fixed composition rule, collect the following three methods to solve the problem
Method one, public int
indexOf(String str) returns the index where the specified substring first appears in this string. The returned integer is This.startswith (str,
k) to
true
The minimum
kValue.
Parameters:
str
-Any string.
return:If the string argument appears as a substring in this object, the index of the first character of the first such substring is returned, and if it does not appear as a substring, it returns
-1
。 if (Str1.indexof ("ro") >=0 | | str1.indexof ("EL") >=0 | | str1.indexof ("RO") >=0) {exists} method two, public boolean
contains(Charsequence s) returns True when and only if this string contains a sequence of specified char values.
Parameters:
s
-Sequence to search (note: The String class is an entity class that implements the Charsequence interface)
return:If this string contains
s
, returns True, otherwise returns false for example: Str.
contains ("12334"
)Note:, meaning that the string "12345" appears in the STR string for any one of the five characters, then it returns true; Method Three, through the regular expression +
matchesMethod public Boolean
matches(string regex) tells whether this string matches a given regular expression.
The str. Matches (regex) form that calls this method produces exactly the same result as the following expression:
Pattern
.
matches
(
regex ,
str )
-
Parameters:
regex
-A regular expression to match this string
-
returns: true if and only if this string matches the given regular expression
[Reprint]java string Fuzzy match (