I'm adding tooltip to certain words in a text. I guess since words with tooltips are not considered as strings, it gives the ~~
operators before and after the word in the result. Needless to say, I don't need them in the result. I have a huge text and thousands of words so looking for a fast-running operation. Thanks
txt = "Good, better, best. Never let it rest. 'Til your good is
better and your better is best.";
words = {"good", "better", "best"};
tooltips = {"good2", "better2", "best2"};
sw = {words, tooltips}\[Transpose];
wordsWithTooltips = Tooltip[#[[1]], #[[2]]] & /@ sw;
tls = {words, wordsWithTooltips}\[Transpose];
StringReplace[txt, #[[1]] -> #[[2]] & /@ tls]
Result:
Good, ~~better~~, ~~best~~. Never let it rest. 'Til your ~~good~~ is ~~better~~ and your ~~better~~ is ~~best~~.
Side question; note that first word (Good) didn't get a tooltip since it starts with a capital letter. How can I set IgnoreCase
to True
in this type of setting?