SQLite - replace part of a string
And if you just want to do it in a query without lasting consequences:
SELECT fieldA, replace(field, 'C:\afolder\', 'C:\anewfolder\'), fieldB FROM table;
You can use the built in replace()
function to perform a string replace in a query.
Other string manipulation functions (and more) are detailed in the SQLite core functions list
The following should point you in the right direction.
UPDATE table SET field = replace( field, 'C:\afolder\', 'C:\anewfolder\' ) WHERE field LIKE 'C:\afolder\%';
@Andrew answer is partially correct. No need to use WHERE
clause here:
- Only fields containing
C:\afolder
will be affected anyway, no reason to check it. It's excessive. 'C:\afolder\%'
will choose only fields starting withC:\afolder\
only. What if you have this path inside string?
So the correct query is just:
UPDATE table SET field = replace( field, 'C:\afolder\', 'C:\anewfolder\');