I would like to use Replace function in a QGIS model but it doesn't work as I wish. I was working with Joseph's brilliant solution (using a custom script in a model) but I couldn't find out how to replace a specific character in a field. I would like to replace every '\' in Fromfield with '/' and write the result into Tofield. I tried this and a few more, but nothing:
##Test=name ##Layer=vector ##Tofield=Field Layer ##Fromfield=Field Layer from qgis.core import QgsExpression layer = processing.getObject(Layer) layer.startEditing() idx = layer.fieldNameIndex(Tofield) g= str(Fromfield) e = QgsExpression(g.replace("\\","/")) e.prepare(layer.pendingFields()) for f in layer.getFeatures(): f[idx] = e.evaluate(f) layer.updateFeature(f) layer.commitChanges()
Is this possible at all?