QGIS – Labelling Strings With First Letter of Each Word

labelingqgisqgsexpressionstring

I have a field called "Species" which is composed by two words (e.g. 'Robinia pseudoacacia') and I would like to extract the first letter of both the words in order to get two letters (e.g. 'Rp') in the label.

There other word pairs in the field "Species" so I guess it needs a rule which specifies that the extraction must be done for the first word (e.g. substr("Species", 1, 1)) as well as for the first letter after the space.

Best Answer

Here's a Regular Expression method, assuming you're doing this in the QGIS Field Calculator:

 regexp_substr("yourfield",'\\w{1}') || regexp_substr("yourfield",' (\\w){1}')
Related Question