Is there a string manipulation to superscript certain values?

I am using a String Manipulation node in KNIME to join some columns:

join($surname$, ", ", $given-names$, toEmpty($xref$))

Is it possible to have all values within the $xref$ column be superscripted?

I’m not sure if this is even possible, but for added context, the data within these columns has been parsed from some XML documents and the xref column may contain numbers or special characters like *, ‡, †, etc.

Hi there!

Not sure you can do this with String Manipulation node. Maybe try Java Snippet node.
Check this out:



In general (there are a few exceptions in the math segment of the unicode standard,) there are no superscripted characters. Superscripting is a styling of text, and strings are just the text with no way to store styling hints; what you see on your screen is the result of something (for example that KNIME output table dialog) rendering that String content (which, again, has no way to store styling hints.)

Actually I have found a very messy way to do that.
You have to aggregate all the characters in “xref” column (in all rows) in a single cell and then copy the cell and use this website to convert the characters to superscripts and then you can use a String Manipulation node to replace characters. Here is an example:

Use a GroupBy node and the Concatenate function on the “xref” column (without any grouping columns), then a String Manipulation node with this expression:
regexReplace(replace($Concatenate(xref)$, ", ", ""), "(.)", "$1,")
Now by using a Cell Splitter node convert it to a Set. And finally a Split Collection Column and a Column Combiner to convert the collection to string without the commas.
Now you have something like this:
copy this to the website I mentioned earlier and get the superscripts.
Now you can use a String Manipulation with this expression to convert the characters:
replaceChars($xref$, "123dht*‡", "¹²³ᵈʰᵗ*‡")
If you have all the possible characters in “xref” column, then you do not have to repeat the first part. Just convert them all at once at the website and use the String Manipulation to replace them.
It is a good idea to have a function to do that in String Manipulation.



An interesting hack, which could be localized entirely to KNIME by finding out what unicode characters are being used for those superscripted characters and then do a mapping in, for example, the Java Snippet node.

To be an annoying pedant, this will still not produce the results of a correctly styled superscripting rendered as we’re used to on the web, or in word processors, or …
The mapping done on the website takes what it can get - as you can see in their example of “superscript” that looks a bit like crumbling clods of mud.



This one is on you. :wink:


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.