Skip to main content

RegEx, FontEncoder and StringReplacer experts, please help!

 

I want to replace regular text characters in a text string attribute with entirely different unicode characters, and be able to use them as geographical labels.

For instance, let's say that I want to convert the character "A" (unicode U+0041) in my text attribute, to the Roman numeral "I" (unicode U+2160), and label my map with that.

 

Some other characters should use other conversion codes - maybe using a lookup table.

 

Is it possible?

Will there be multiple replacements per text string?


Will there be multiple replacements per text string?

It's a 1:1 substitute.

If the text string is "AxyAx" (x, y being any other characters), every "A" should be substituted with one instance of the new unicode character (the roman numeral "I" in my example). Resulting in "IxyIx" (if I do not also substitute the x and y characters with something just yet).

 

The roman numeral is just an example; what I am ultimately looking for is to be able to convert some place names (text strings) into runic alphabet symbols https://en.wikipedia.org/wiki/Runic_(Unicode_block)

and replace the map labels with that, where it's possible. 😉


It's a 1:1 substitute.

If the text string is "AxyAx" (x, y being any other characters), every "A" should be substituted with one instance of the new unicode character (the roman numeral "I" in my example). Resulting in "IxyIx" (if I do not also substitute the x and y characters with something just yet).

 

The roman numeral is just an example; what I am ultimately looking for is to be able to convert some place names (text strings) into runic alphabet symbols https://en.wikipedia.org/wiki/Runic_(Unicode_block)

and replace the map labels with that, where it's possible. 😉

But will there be multiple replacements of different characters in the same string?

 

Have you already ruled out the StringPairReplacer?


It's a 1:1 substitute.

If the text string is "AxyAx" (x, y being any other characters), every "A" should be substituted with one instance of the new unicode character (the roman numeral "I" in my example). Resulting in "IxyIx" (if I do not also substitute the x and y characters with something just yet).

 

The roman numeral is just an example; what I am ultimately looking for is to be able to convert some place names (text strings) into runic alphabet symbols https://en.wikipedia.org/wiki/Runic_(Unicode_block)

and replace the map labels with that, where it's possible. 😉

StringPairReplacer looks like a possible way, but how do I convert to a new unicode and populate the new label attribute with that, so that I can use it on a map?

 


It's a 1:1 substitute.

If the text string is "AxyAx" (x, y being any other characters), every "A" should be substituted with one instance of the new unicode character (the roman numeral "I" in my example). Resulting in "IxyIx" (if I do not also substitute the x and y characters with something just yet).

 

The roman numeral is just an example; what I am ultimately looking for is to be able to convert some place names (text strings) into runic alphabet symbols https://en.wikipedia.org/wiki/Runic_(Unicode_block)

and replace the map labels with that, where it's possible. 😉

I maybe misunderstanding, but in terms of converting all instances of a character you can just use a string replacer.

imageHow you handle multiple replacements of different characters depends on the answer to my question, will you ever have to replace two different characters in the same string?

 

If multiple replacements, I think a python solution is probably much simpler then any a pure FME option


It's a 1:1 substitute.

If the text string is "AxyAx" (x, y being any other characters), every "A" should be substituted with one instance of the new unicode character (the roman numeral "I" in my example). Resulting in "IxyIx" (if I do not also substitute the x and y characters with something just yet).

 

The roman numeral is just an example; what I am ultimately looking for is to be able to convert some place names (text strings) into runic alphabet symbols https://en.wikipedia.org/wiki/Runic_(Unicode_block)

and replace the map labels with that, where it's possible. 😉

Yes, there will be multiple replacements but the StringPairReplacer should be able to do that. But just typing in ”A u2160” won’t work, that will just give me the label ”u2160”, not a Roman ”I”.


It's a 1:1 substitute. 

If the text string is "AxyAx" (x, y being any other characters), every "A" should be substituted with one instance of the new unicode character (the roman numeral "I" in my example). Resulting in "IxyIx" (if I do not also substitute the x and y characters with something just yet).

 

The roman numeral is just an example; what I am ultimately looking for is to be able to convert some place names (text strings) into runic alphabet symbols https://en.wikipedia.org/wiki/Runic_(Unicode_block)

 and replace the map labels with that, where it's possible. 😉 

The StringPairReplacer doesn't appear to be able to handle the characters, and so if there are multiple the best option would be delving into python I think

 

import fme
import fmeobjects
 
def processFeature(feature):
    mydict = {"\u0041":"\u2160","\u0042":"\u16B0"}
    s = feature.getAttribute('name')
    for a,b in mydict.items():
        s = s.replace(a,b)
    feature.setAttribute("replaced",s)

 


Reply