Reformatting author names

Hello,

I'm a newbie in javascript and I'm using the Adam Crymble's tutorial to write a translator.
I need to reformat author names: I have to check if there is one author and to reverse the order last name/first name.
My script is ok for single author. However I don't find the solution for multiple author.
The syntax seems ok but I might been mistaken on the regexp...
Authors are separated by a
and first name/last name by a comma and a white space (", ").

Thank you so much if you can have a look on my code: it is so frustrating after hours...

if (itemTypes["Auteur(s)"]) {
    var author = itemTypes["Auteur(s)"];
    if (author.match(/\s{2}/)) {
      var authors = author.split(/\s{2}/);
      for (j = authors.length-1; j>-1; j--) {
        var words = new Array();
        words[j] = authors[j].split(", ");
        var authorFixed = '';
        for (i = words[j].length-1; i > -1; i--) {
          authorFixed = authorFixed + words[i] + ' ';
          }
          for (var i in authors) {
          newItem.creators.push(Zotero.Utilities.cleanAuthor(authorFixed[i], 'author'));
          }

          }
      } else {
        var authorName = itemTypes["Auteur(s)"];
        var words = authorName.split(", ");
        var authorFixed = '';
        for (i = words.length-1; i > -1; i--) {
          authorFixed = authorFixed + words[i] + ' ';
        }
        newItem.creators.push(Zotero.Utilities.cleanAuthor(authorFixed, 'author'));
        }
  • zotero-dev is a better place for technical questions like this.
  • edited November 14, 2009
    Ok. Sorry! You can close the topic. I'll post on zotero-dev. Thanks
  • When you post there, an example URL you're trying to create a translator for (or, at the very least, an example input string, but there may be a better solution than string processing) would probably also help.
Sign In or Register to comment.