<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def utf8_encode_str(string, encoding='UTF-8'):
 """Attempt to detect the native encoding of `string`, and re-encode to utf-8 :type string: str :param string: The string to be encoded. :rtype: str :returns: A utf-8 encoded string. """

    if not string:
        return ''
    src_enc = chardet.detect(string)['encoding']
    try:
        return string.decode(src_enc).encode(encoding)
    except:
        return string.decode('ascii', errors='replace').encode(encoding)