Using splitto count is not the most efficient, but if you insist on it, the correct way is this:
haystack.split(needle, -1).length -1
limit -1, split - 0, , .
API:
, , . [...] n , [...] .
1 length , n N+1.
(.. needle), \b word. word (, "$US"), Pattern.quote it.
:
numThe += line.split("[^a-zA-Z][Tt]he[^a-zA-Z]", -1).length - 1;
. ( ), .
, [Tt]he, , , / , [^a-zA-Z] ( , 5!). , !
- :
"(^|[^a-zA-Z])[Tt]he([^a-zA-Z]|$)"
, .
- ( ) :
"(?<![a-zA-Z])[Tt]he(?![^a-zA-Z])"
[Tt]he, - , . , , split, "" - .
Non- split
split , (, , ). , , , , .
, , Pattern.compile while (matcher.find()) count++;