def _sanitize(hex_str, comment_strings=None, ignore_strings=None):
    """
    Sanitize string input before attempting to write to file.

    :param hex_str: the string input to sanitize
    :param comment_strings:  a tuple of strings identifying comment characters
    :param ignore_strings:  a tuple of strings to ignore in the input
    :return: the sanitized string or None
    """
    hex_str = hex_str.strip()
    if not hex_str:
        return None
    if comment_strings:
        for comment_string in comment_strings:
            if hex_str.startswith(comment_string):
                return None
            else:
                hex_str = hex_str.split(comment_string)[0]
    hex_id = '0x'
    if ignore_strings:
        ignore_strings += hex_id,
    else:
        ignore_strings = hex_id,
    for string_to_remove in ignore_strings:
        hex_str = hex_str.replace(string_to_remove, '')
    return ''.join(hex_str.split())
