I recently discovered an interesting trick that allows to "Split String With String As Delimiter", so I couldn't resist the temptation to post it here as a new answer. Note that "obviously the question wasn't accurate. Firstly, both string1 and string2 can contain spaces. Secondly, both string1 and string2 can contain ampersands ('&')". This method correctly works with the new specifications (posted as a comment below Stephan's answer).
@echo off
setlocal
set "str=string1&with spaces by string2&with spaces.txt"
set "string1=%str: by =" & set "string2=%"
set "string2=%string2:.txt=%"
echo "%string1%"
echo "%string2%"
For further details on the split method, see this post.