"Ending with" vs "ending in" [duplicate]
I'm writing up some documentation, and I'm unsure which phrase to use:
Option X: Find all strings ending with
foo
.
or
Option X: Find all strings ending in
foo
.
Are both correct? (Google spits out both, strongly favoring with.) Which should I prefer?
"Ends in" is acceptable in the sense that words can end in a vowel; end in an "a"; etc. This is often shortened to:
"Word" ends in "d"
"Ends with" seems to fulfill the same use:
"Word" ends with "d"
But I typically think of "ends with" using larger things than letters:
"This phrase" ends with "phrase"
"This is a sentence" that ends with "sentence"
Really, though, both "in" and "with" are doable:
"Hungry" and "angry" both end in "gry."
"Hungry" and "angry" both end with "gry."
The only difference I can find is their usage outside of words:
Our journey ends in Texas.
Our journey ends with disaster.
To directly answer your question, both work just fine in the original context. Some people prefer one over the other; some workplaces will have a strict style guide dictating which should be used. At the end of the day, consistency is more important.
As for references, there isn't much to find other than looking at hits via Google. NGram searching for "ends in/with c" shows:
But that really doesn't mean much, given the propensity for quirks in searching algorithms. Just browsing pages found by Google is of virtually no help given how often people use both phrases.
Close call. I would say that "in" is asking for a very precise case, whereas "with" is for more general usage. For example:
Which words end in "ces"?
but
Which words end with a vowel
Both are acceptable. The difference is very subtle and is a matter of style.
end in is a phrasal verb
- end in [something]
- end [something] in [something]
end with is a phrasal verb
- end with [something]
- end [something] with [something]
Notice that end in has a specific usage "the meeting ends in disaster" to specify the result, while "the meeting ends with disaster" states the sequence of unrelated events, "the show ended with another famous song".
So if there is a logical connection you may use end in like in
Plural usually ends in -s.
This is making a small logical connection between ending -s and something being plural. You have established the cause in both directions.
If you just want to state how a word ends, with has no such connection "elephant ends with -phant". But: "aluminum ends in -um", because other chemical elements end in -um as well.
The difference is really subtle, and is a matter of style.
So in your example, if you really want to be pedantic and follow some common style, you would use in in case "foo" has some particular meaning, otherwise you use with. This is nothing like a rule, just a point into a direction of making difference between the two, showing the logical layer where they may differ.
Find the first file with the name ending in .txt (suggesting it is a recognizable extension, additionally avoiding double with ... with)
I would go with
Option X: Find all strings ending with foo.
It sounds more solid.