Vyxal, 13 bytes
2lƛvh≈0ẋntc;∑
Try it Online or run all the test cases.
How?
2lƛvh≈0ẋntc;∑
2l # Get a list of overlapping pairs in the (implicit) first input
ƛ # Map over them:
vh # Get the first character of both
≈ # Are they equal?
0 # Push the second input
ẋ # Repeat (so if the first characters are not equal, empty string, else second input)
n # Push the pair again
t # Get the second item in the pair
c # Does the other string contain this string?
; # Close map lambda
∑ # Summate
Vyxal, 13 bytes
2lƛvh≈0ẋntc;∑
Try it Online or run all the test cases.
How?
2lƛvh≈0ẋntc;∑
2l # Get a list of overlapping pairs in the (implicit) first input
ƛ # Map over them:
vh # Get the first character of both
≈ # Are they equal?
0 # Push the second input
ẋ # Repeat (so if the first characters are not equal, empty string, else second input)
n # Push the pair again
t # Get the second item in the pair
c # Does the other string contain this string?
; # Close map lambda
∑ # Summate