Reputation: 53
I need help transforming this:
/storage/emulated/0/Android/data/testapp/files/textToDelete
into this
/storage/emulated/0/Android/data/testapp/files/
note: I don't want to use static value substring
Upvotes: 2
Views: 1855
Reputation: 14033
// the string to be trimmed
var myString = '/storage/emulated/0/Android/data/testapp/files/textToDelete';
// substring the string using the last index of the character + 1
var trimmedString = myString.substring(0, myString.lastIndexOf('/') + 1);
// print the trimmed string
print(trimmedString);
OUTPUT: /storage/emulated/0/Android/data/testapp/files/
Upvotes: 4