Skip to main content
Solved

How to generate next letter of alphabet?


lazarlubomir
Contributor
Forum|alt.badge.img+7

Hello everyone, is there any way how to generate next letter of alphabet? E.g I have feature with value "A" and I wanna generate next letter in alphabet, so letter "B". Is there any function for that?

 

Thanks a lot!

 

Lubo

Best answer by david_r

You can use the CharacterCodeExtractor to convert the letter to an integer value, increment the value with an ExpressionEvaluator, then convert it back to a letter using the CharacterCodeReplacer.

For reference, you're incrementing over the Unicode symbols, see https://symbl.cc/en/unicode/table/

The value below each symbol in hexadecimal, e.g. "A" = 41 hex = 65 decimal

View original
Did this help you find an answer to your question?

6 replies

david_r
Celebrity
  • Best Answer
  • October 16, 2023

You can use the CharacterCodeExtractor to convert the letter to an integer value, increment the value with an ExpressionEvaluator, then convert it back to a letter using the CharacterCodeReplacer.

For reference, you're incrementing over the Unicode symbols, see https://symbl.cc/en/unicode/table/

The value below each symbol in hexadecimal, e.g. "A" = 41 hex = 65 decimal


nielsgerrits
VIP
Forum|alt.badge.img+54
david_r wrote:

You can use the CharacterCodeExtractor to convert the letter to an integer value, increment the value with an ExpressionEvaluator, then convert it back to a letter using the CharacterCodeReplacer.

For reference, you're incrementing over the Unicode symbols, see https://symbl.cc/en/unicode/table/

The value below each symbol in hexadecimal, e.g. "A" = 41 hex = 65 decimal

Nice! Learned something new today :)


geomancer
Evangelist
Forum|alt.badge.img+50
  • Evangelist
  • October 16, 2023
nielsgerrits wrote:

Nice! Learned something new today :)

Me too, I was looking into a much more complicated solution 😄


lazarlubomir
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • October 16, 2023
david_r wrote:

You can use the CharacterCodeExtractor to convert the letter to an integer value, increment the value with an ExpressionEvaluator, then convert it back to a letter using the CharacterCodeReplacer.

For reference, you're incrementing over the Unicode symbols, see https://symbl.cc/en/unicode/table/

The value below each symbol in hexadecimal, e.g. "A" = 41 hex = 65 decimal

Great solution! I have known just NumToAlpha Converter (https://hub.safe.com/publishers/pacific-spatial-solutions/transformers/numtoalphaconverter), but Your solution is perfect for my usecase. Thank You so much @david_r​ !


hkingsbury
Celebrity
Forum|alt.badge.img+55
  • Celebrity
  • October 16, 2023
david_r wrote:

You can use the CharacterCodeExtractor to convert the letter to an integer value, increment the value with an ExpressionEvaluator, then convert it back to a letter using the CharacterCodeReplacer.

For reference, you're incrementing over the Unicode symbols, see https://symbl.cc/en/unicode/table/

The value below each symbol in hexadecimal, e.g. "A" = 41 hex = 65 decimal

@david_r​ thats a really cool approach. I was about to ask how do you think you'd solve the wrap around when you get to 'Z' and you then want to have 'AA'. But thinking about it you could keep incrementing and use fmod() to figure out what the second char should be


david_r
Celebrity
  • October 17, 2023
hkingsbury wrote:

@david_r​ thats a really cool approach. I was about to ask how do you think you'd solve the wrap around when you get to 'Z' and you then want to have 'AA'. But thinking about it you could keep incrementing and use fmod() to figure out what the second char should be

To be honest I'd probably do that part in Python ;-) There are some possible starting points here: https://stackoverflow.com/questions/42176498/repeating-letters-like-excel-columns

But yes, you could probably also do it in FME combining modulo and integer division, but I suspect it would be somewhat involved unless you do it in a looping custom transformer.


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