I have an unwanted space in my data attribute field after copying the data as you see below.

enter image description here

Is there any way to remove it automatically (i.e. when I select another attribute field)?

  • Try [trim](https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/functions_list.html?highlight=trim#trim). But once again, this works only after you created the entry to the attribute table, not while it "floats around".
    – Erik
    Jul 29 at 9:22
  • Ok, I see, but how to apply it into the Defaults? I have put something like this: trim('') but it didn't work
    – MKR
    Jul 29 at 9:32

Depending on your workflow and based on other suggestions/answer to use the Trim function, I would approach removing the space(s) in the following way. Once the data copying to the attribute table is complete, I would simply use Update existing field from the Field calculator. Once complete simply save.

I tried it on QGIS 3.10.12 and it work. (Pls note create a back up before you update).

enter image description here


If you want to use trim() in default value, you have to generate a new field, for example "span_name_2", where you write value with space.

And setting in "span_name" field as default value:


so automatically in 'span_name' is memorized text without space.

  • Is it possible to do it without creating the new column?
    – MKR
    Jul 29 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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