Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

removing multiple possible suffixes from linked files names js

Community Expert ,
Sep 07, 2008 Sep 07, 2008
Good monday-morning!
I work on a Script that relinks images with ones that have been separated according to other print-conditions and carry some suffix to indicate this; to get it to recognize the correct ones I need to remove potential existing suffixes ("_lay" for example but also signifiers for other separations) from the linked images names.
I get this to work with either a series of »replaces« or a »for«-clause and an array of the possible suffixes, but Im only looking for a more elegant or simple way to do this in JavaScript.
So what would in Your valued opinions be the most concise way to remove a host of possible letter-combinations from a String?

Thanks for any advice
pfaffenbichler
TOPICS
Scripting
856
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 07, 2008 Sep 07, 2008
hi christoph,
I had a simililar problem for adnumbers, that I solved with a regular expression.

String.prototype.getAdnumber = function () {
var reg = new RegExp("\\d+");//any Number at the beginning of the string
var myString = reg.exec(this);
return myString;
}

You need to find the correct expression for your needs.

Stefan
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2008 Sep 10, 2008
Thanks, Stefan, and please forgive my late reply, but work has picked up the pace lately.
I hope I will be able to consider Your proposal more thoroughly sometime soon.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 10, 2008 Sep 10, 2008
Hi Christoph,

If suffixes are delimited by underscore, which used only once in a file name, then you can get rid of them in this way:


var myOldLinkName = myLink.name;
// I assume that all extensions consist of 3 characters
var myExtension = myOldLinkName.substr(-4, 4);
var myNewLinkName = myOldLinkName.split("_", 1).join() + myExtension;

Kasyan
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2008 Sep 10, 2008
Thanks, Kasyan.
Unfortunately the naming-discipline is more lax than desirable around here ...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 10, 2008 Sep 10, 2008
Im sure this is solvable.
Could you give me examples of all possible suffixes in your workflow?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2008 Sep 10, 2008
Possible suffixes are " end", "_end","_lay", " lay".
It certainly is solvable, but what would be the most economic or elegant way is where Im out of my depth.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2008 Sep 11, 2008
This deletes any combination of suffixes:

for (i = 0; i < 4; i++)
link_name = link_name.replace (/[ _](end|lay)$/g, "");

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2008 Sep 11, 2008
LATEST
Thanks, Peter.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines