How to replace characters(like A-Z) in a string with their corresponding ASCII codes(like 65-90) in bulk?
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 -> ??
Decimal representation(e.g. ABC ->656667)
,Decimal representation?e.g. ABC ->656667?
Decimal representation(e.g. ABC ->656667)
This is a possible way - split the string into individual characters, extract their ASCII code (CharacterCodeExtractor), then concatenate them (Aggregator).
... 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 {}]
}
It works. Thanks a lot.
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.