TransWikia.com

How to get a text character based on a number position in the alphabet in a QGIS expression

Geographic Information Systems Asked on June 10, 2021

This seems very simple but I can’t find a function that will take a number between 1 and 26 and return the right letter.
1=A
2=B
3=C

Z=26

One Answer

You can use this QGIS expression: replace the number 1 at the second last line with any number from 1 to 26 to get the corresponding letter - if you set it to 5, it will return E:

map_get(
    hstore_to_map( 
        array_to_string (
            array_foreach (
                generate_series (1,26),
                to_string (
                    @element || '=>' || char (@element+64)
                )
            )
        )
    ),1
)

You could use a custom variable instead of the number to be more flexible and get the current value of the variable from somewhere else.

Answered by Babel on June 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP