Strings¶
Find text after last occurrence of separator¶
select replace(str, rtrim(str, replace(str, '/', '')), '') from table;
How to get the last index of a substring in SQLite?
Explanation:
for example we have the string: /storage/udisk/1200 Mics/[2002] 1200 Micrograms/1200 Mics - 03 - Mescaline.mp3
replace(str, '/', '')
- removes / chars from str so we will have storageudisk1200 Mics[2002] 1200 Micrograms1200 Mics - 06 - Ecstasy.mp3
next we use rtrim it will remove all matching chars from right to the left until it finds the / char and this way we found our parent dir: /storage/udisk/1200 Mics/[2002] 1200 Micrograms/
now we remove the parent path name from the file path and we have the filename 1200 Mics - 03 - Mescaline.mp3