7

I have a field called "Genus" where there are string values, for example, the word 'Pinus'.

I want my label to show only the first letter of this word so in my example 'P'.

I was trying to use Function Editor. I was contriving with field.row[0], but I'm not sure with the rest of the syntax.

Maybe there is another solution for it?

4 Answers 4

13

Use this in your label composer, it should do the trick :

left("Genus", 1)

Here's a list of functions you can use in your expressions

0
12

Another way is to use the substr() function:

substr("FieldName", 1, 1)

enter image description here

Replace "FieldName" with the name of your field.

Output:
enter image description here

0
1

Another solution employs the regexp_substr() function:

regexp_substr("data", '^[[:alpha:]]|[0-9]')

result

1

There is also a solution that uses the array_to_string() function.

string_to_array("test", '')[1]

Note: here I am referring to the fist character via [1] and not [0] (because it is a space even though initially there is no space in the string).

result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.