I have text that contains a zero-width character that I am not able to remove. A minimum example is in str
below where the character is at the start of the text.
str = "4-6";
res = ToExpression /@
StringSplit[StringReplace[str, WhitespaceCharacter -> ""], "-"]
{4, 6}
Head /@ res
{Symbol, Integer}
This character (or these types of characters) are at various locations in the imported text.
They do not appear to fall into WhitespaceCharacter
as StringReplace
does not match to them and I don't know their locations before-hand so I can't use StringReplacePart
.
How do I clean these unknown zero-width character from strings?
StringSplit[str, Except[WordCharacter]]
? It would remove white space characters including the ones overlooked byWhitespaceCharacters
. Your example doesn't look as if you want to remove only the two invisible ones. $\endgroup$CharacterEncoding -> "ASCII"
and then remove the offending\:xxxx
. $\endgroup$