to_valid_utf8
stringConverts invalid UTF-8 sequences to valid UTF-8
Syntax
to_valid_utf8(string) Parameters
string (string) The string to convert to valid UTF-8
Returns
string String with valid UTF-8 encoding
Examples
Input:
to_valid_utf8("hello") Output:
"hello" Input:
"test data" | to_valid_utf8 Output:
"test data" The to_valid_utf8() function converts a string with potentially invalid UTF-8 sequences into a valid UTF-8 string, replacing or removing invalid sequences.
Usage
Use to_valid_utf8() for cleaning text data from unreliable sources, ensuring encoding compatibility, or preventing errors in UTF-8 strict systems.