Using the field calculator to replace the character in QGIS

Use this expression: if(left(linecode, 1) = '-', substr(linecode, 2) + 'B', linecode + 'F')

I suggest to create new field instead of changing the existing one. You may need the original one later.


You can use regexp_replace function in field calculator:

enter image description here

The expression

regexp_replace(  "linecode", '^-(.*)$', '\\1B')

will replace '-' + 'any string' with 'any string' + 'B'. So it will change string '-0345' to '0345B'. \\1 refer to the expression part in brackets. You may give more specific regexp instead of '.*'.

enter image description here

The second expression will add 'F' to numeric strings:

regexp_replace( "linecode", '^([0.9][0-9]*)$', '\\1F')

It will replace only string made of numeric characters [0.9], so you can use it after the previous expression without selection in the table.