TransWikia.com

Removing last part of a field in QGIS attribute table, not the same length of cells

Geographic Information Systems Asked by John Isaiah L. on April 23, 2021

I got a question regarding removing and/or creating a new field just with the 4 first characters of a field. Whenever I search for this I just find answers about how to remove a specific number of values from the front or the back, the problem here is that I have fields with a 4 digit number and then different names! like for example "2481 New York" and the next one "4521 Seattle" and I want a new field with only the first digits!

One Answer

There are a few possible options to achieve the desired result.

You could use a substring function to extract the first 4 characters:

substr("YourFieldName",1,4)

Another possibility is to use the following regex function which extracts numbers appearing at the beginning of a string:

regexp_substr("YourFieldName",'^d+')

The advantage of the last one is that it can handle cases with varying number lengths.

I recommend to test this in a new field first before potentially updating your actual field, to check that the result is as you intended.

Answered by FSimardGIS on April 23, 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