Skip to main content
Question

How to replace characters(like A-Z) in a string with their corresponding ASCII codes(like 65-90) in bulk?


fmelizard
Safer
Forum|alt.badge.img+19
How to replace characters(like A-Z) in a string with their corresponding ASCII codes(like 65-90) in bulk?

5 replies

takashi
Evangelist
  • April 6, 2016

Hi @FMEZipster, you can use the TextEncoder (Encoding Type: HEX) to translate every character within a string to ASCII code with hexadecimal representation.

If you need to convert the result to decimal representation and/or comma-separated format, need some additional transformers or other approach. What representation do you need finally? e.g. ABC -> ??


  • April 6, 2016

Decimal representation(e.g. ABC ->656667)

,

Decimal representation?e.g. ABC ->656667?


  • April 6, 2016

Decimal representation(e.g. ABC ->656667)


takashi
Evangelist
  • April 6, 2016

This is a possible way - split the string into individual characters, extract their ASCII code (CharacterCodeExtractor), then concatenate them (Aggregator).

0684Q00000ArLeeQAF.png

... scripting might be easier in this case.

PythonCaller script example:

def extractAsciiCode(feature):
    codes = [str(ord(c)) for c in feature.getAttribute('_src')]
    feature.setAttribute('_codes'''.join(codes))

TclCaller script example:

proc extractAsciiCode {} {
    set codes {}
    foreach ch [split [FME_GetAttribute "_src"] {}] {
        lappend codes [scan $ch %c]
    }
    return [join $codes {}]
}

  • April 8, 2016

It works. Thanks a lot.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings