StringReplace["abbaabbaa", "ab" -> "X"] will output XbaXbaa, but StringReplace["abbaabbaa", "ab" -> Style["X", Red]] outputs
It is weird, as why there are horizontal lines between the replaced characters and other characters?
StringReplace["abbaabbaa", "ab" -> "X"] will output XbaXbaa, but StringReplace["abbaabbaa", "ab" -> Style["X", Red]] outputs
It is weird, as why there are horizontal lines between the replaced characters and other characters?
Cannot find an exact duplicate at the moment, but the solution is mentioned at least in the following 3 posts:
https://mathematica.stackexchange.com/a/77842/1871
https://mathematica.stackexchange.com/a/213639/1871
https://mathematica.stackexchange.com/a/246756/1871
StringReplace["abbaabbaa", "ab" -> ToString[Style["X", Red], StandardForm]]
StandardForm like ToString[StringReplace["abbaabbaa", "ab" -> Style["X", Red]], StandardForm] before resorting to the embarassing workaround I posted.
– Syed
Sep 20 '23 at 05:12
Row@(List @@ StringReplace["abbaabbaa", "ab" -> Style["X", Red]])? Do a//FullFormat the end of an expression to see its internal structure. – Syed Sep 20 '23 at 04:58ToStringcan solve this problem. It is a little difficult to understand it. – Y. zeng Sep 20 '23 at 05:07Style["X", Red]is no longer aString. – xzczd Sep 20 '23 at 05:08ToStringto convert it to aString. You may argue the output is confusing and need to be improved, though. – xzczd Sep 20 '23 at 05:09~~is displayed, not--. – xzczd Sep 20 '23 at 05:14~~, sometimes--. Very weird. – Y. zeng Sep 20 '23 at 05:18