Given that both prepositions are acceptable in general contexts with a slight deviation in usage, meaning, and voice ("Replace with" versus "replace by" has a too wide scope), let us narrow the task down semantically and vary only the form of "replace". Here, we are going to speak only about replacing in the sense of substituting substrings of strings by/with other substrings.

The following sentences in question are short versions of somewhat more complicated sentences taken from the description of some algorithm. The sentences have been uniformized to abstract from irrelevant algorithm details:

  1. In the next step, we replace the substring x of the string axby by/with y.
  2. In the next step, replace the substring x of the string axby by/with y.
  3. In the next step, the substring x of the string axby is replaced by/with y.
  4. We proceed by replacing the substring x of the string axby by/with y.
  5. We proceed, replacing the substring x of the string axby by/with y.
  6. The next step is to replace the substring x of the string axby by/with y.
  7. The next step is the replacement of the substring x of the string axby by/with y.

(If anyone is interested: if x occurs neither in a nor in by, the result of the replacement will be ayby.)

How would you formulate the sentences 1–7 and why?

As an aside, notice that the passive form 3 has no agent.

As another aside, if anyone is interested, the algorithm itself has the form


Input: some string

Output: some other string

  • do foo
  • do bar
  • do bla


I have several options of how to write down the "do xxx" parts using any style in the range 1–7. Moreover, a few versions of the algorithm are scattered around the paper. The paper is going to be submitted to a serious computer science venue.


2 Answers 2


Both options are ambiguous, but 'with' is the better choice.

String 'x' is replaced with 'y', by the computer, using the algorithm.

'By' can refer to the 'agent' of a passive clause.
'With' can refer to an 'instrument' (tool), but 'using' is stronger.

FYI, note the ambiguity here: (because robots can be agents, patients or instruments)

Robot A was replaced with Robot B, by Robot C, using Robot D.

Robot A was replaced by Robot ___. (B or C?)

Robot A was replaced with Robot ___. (B or D?)

  1. Wow! The algorithm, even in their concise forms can be overwhelming. When I am confronted with such intimidating statements, it would be best to use "Replace/d with" all throughout whatever that is you're working on. Replace+with has never failed me. Replace+by invites doubts and unwelcome criticism and might even expose my deficiencies in such topics as like what you have presented here. If you must, Replace/d+with to everything and even to the very last of your breath. As I know I will.

  2. Since you used the word "substituting" in your question, I'd like to mention that though the definitions of "Substitute" and "Replace" are similar but not really the same. Though I can point out that if you use the word "Substitute", the following rules with regards to the order of what or who is being substituted apply:

―Substitute+with ➞ Old With New (or OWN first letters)

―Substitute+for ➞ New For Old (NFO but you only need to remember OWN above to decipher this).

  1. Now both Replace and Substitute + WITH have the same rules on order.

―REPLACE + WITH ➞ Old With New (OWN).

  1. To conclude:

―REPLACE and SUBSTITUTE + WITH ➞ OWN *Always a sure thing.

―SUBSTITUTE + FOR ➞ NFO *Always a sure thing.

*** REPLACE + FOR ➞ *Never a sure thing for me so why the heck use it ?

*** REPLACE + BY ➞ *Shouldn't a date or time succeed such in this form, and in this case there is no need to mention the date or time it is replacing. I just don't live my life on the edge to be considering this. Why gamble ? Ha ! But this is me of course.

  • Please add citations for where these rules come from.
    – CJ Dennis
    Feb 19, 2020 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.