def count_encoded_characters(string):
    """Count encoded number of characters.

    "" -> "\"\""
    "abc" -> "\"abc\""
    "aaa\"aaa" -> "\"aaa\\\"aaa\""
    "\x27" -> "\"\\x27\""
    """
    return len(string.replace('\\', '\\\\').replace('"', r'\"')) + 2