If the string is rigid , tight, inextensible with tension > 0, then the two bodies have the same (magnitude of) acceleration, along the direction of the string on either side.
If the string is loose or folded, then the accelerations cannot be inter-related easily.
I suppose there is no rotation of the two bodies..
Is this question / doubt from the topic pulleys, bodies attached to strings rolling over pulleys? Then yes, certainly.