Find wall segment length between 2 spaces

I am trying to find a way to get the wall segment lenght between 2 spaces. That segment could be the entire wall but could also be just 1 meter of the wall, and i should find that lenght. Thank in advance.

Hello, don’t forget to provide as much information and tests as possible to get fruitful answers.

Sincerely
christian.stan