def _write_string(record, sub_string, pos):
    """Function that actually writes the generated strings to a 'stream"""
    new_pos = pos + len(sub_string)
    if pos > len(record):
        record = record.ljust(pos)
        out = record + sub_string
    elif pos == len(record):
        out = record + sub_string
    elif pos < len(record):
        out = record[:pos] + sub_string + record[new_pos:]
    return new_pos, out
