<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_string_on_file_between_markers(filename: str, string: str, marker: str):
 r"""Write the table of contents on a single file. :parameter filename: the file that needs to be read or modified. :parameter string: the string that will be written on the file. :parameter marker: a marker that will identify the start and the end of the string. :type filenames: str :type string: str :type marker: str :returns: None :rtype: None :raises: StdinIsNotAFileToBeWritten or an fpyutils exception or a built-in exception. """

    if filename == '-':
        raise StdinIsNotAFileToBeWritten

    final_string = marker + '\n\n' + string.rstrip() + '\n\n' + marker + '\n'
    marker_line_positions = fpyutils.get_line_matches(
        filename, marker, 2, loose_matching=True)

    if 1 in marker_line_positions:
        if 2 in marker_line_positions:
            fpyutils.remove_line_interval(filename, marker_line_positions[1],
                                          marker_line_positions[2], filename)
        else:
            fpyutils.remove_line_interval(filename, marker_line_positions[1],
                                          marker_line_positions[1], filename)
        fpyutils.insert_string_at_line(
            filename,
            final_string,
            marker_line_positions[1],
            filename,
            append=False)