Need help to replace a bunch of different text strings at once time?

Advanced Renamer forum
#1 : 09/05-16 22:20
TimL
TimL
Posts: 2
I have a list of 100 text strings that I want to replace the postfix portion with the 1st letter of each word. For example: Peace - Jone Doe, War - Mike Makie, History - Nixon Vale Dot, Culture - Amit Patel Mint, War - Jone Doe, ...

The ending results should be Peace - JD, War - MM, History - NVD, Culture - APM, War - Jone Doe, .... respectively. Please note the 2nd part (name) is some time associated with different 1st string as well, like the name "Jone Doe" above.

Instead of creating 100 replacement cases individually, can it be a way that I can do it in one single replacement? If the list is too big, then it can be chopped down to smaller lists. Yet that is still much better than replacing 100 cases one at a time.

Thanks so much for your help.


V/r
Tim


09/05-16 22:20 - edited 09/05-16 22:36
#2 : 10/05-16 10:32
Tester123
Tester123
Posts: 92
Reply to #1:
Try this Script Method:

// ----- Start of Script -----
var fileName = item.newBasename;
var separator = " - "
var posSeparator = fileName.indexOf(separator);
var newFileName;
var fileNameSuffix;

// If no separator, leave filename as is
if (posSeparator < 0) {
newFileName = fileName;
}
// Separator found...
else {
// Take filename up to and including the separator
newFileName = fileName.substr(0, posSeparator) + separator;
// After the separator, split each word into an array
fileNameSuffix = fileName.substr(posSeparator + separator.length).trim().split(" ");

// Go through the array and take the first character of each word
for (var j = 0; j < fileNameSuffix.length; j++) {
newFileName = newFileName + fileNameSuffix[j][0];
}
}

return newFileName;
// ----- End of Script -----


10/05-16 10:32 - edited 10/05-16 10:38
#3 : 11/05-16 01:45
TimL
TimL
Posts: 2
Reply to #2:
You're GENIUS. It works perfectly. Thanks so much.


11/05-16 01:45 - edited 11/05-16 01:46