Page 1 of 1

[REQ] Quentin Tarantino --> Tarantino, Quentin Script

Posted: 2009-01-21 11:57:17
by Melmoth
Hi,

I'm looking for a Script that converts a field in the following way:

[first part] space [last part] ---> [last part] comma [first part]
or in words: Quentin Tarantino --> Tarantino, Quentin

AND if possible

move last part to first position, divide it by a comma and put the rest after it, eg. Francis Ford Coppola --> Coppola, Francis Ford

Is that possible? I didn't find anything here...

Thanks in advance,

Melmoth

Posted: 2009-01-21 13:04:17
by antp
Hi,
I was sure that I already wrote that, indeed it was not easy to find, especially since it was in a French thread:
viewtopic.php?p=22616#22616
:hihi:
In this case it was just to swap first and last name, handling properly the lists where names were separated by comma, so I do not know what that should become if you also introduce commas in the names (or maybe you never have more than one name ?)
About the 2nd question, it would be not very difficult to modify the script I guess.

Posted: 2009-01-21 14:10:09
by Melmoth
Wow, that's swift...
The script does almost what I was looking for! I've no clue what the rest of the post said - I hardly speak French - so, if there were any explanations I didn't get them.
If I got the script right (I can only look and guess what those fancy commands may mean) it defines items "i" and "p" and changes their position? So, for my needs I just need a definition "this is the very last item" and a "inject comma" command...?
Or in a nutshell and for dummies: How do I inject a comma? How does this tailoring for longer names (more than 2 items) work?

PS: thanks again for this very great programme! It's not only the greatest one for movies, it is the only good solution for books as well (I really tried hard to find a good programme for that and ended up with AMC again). And whatever you try, no matter how odd or geeky the idea is, it works... amazing!

Thanks,

Melmoth

Posted: 2009-01-22 13:27:27
by antp
"i" is used as counter in the loop which process each name when there are several, "p" is used to store position of the space.
"s" contains currently processed name.
It rebuilds "s" with what is after "p" position then a space/comma, then what is before "p" position.

As I had few minutes, here is a modified script where it replaces commas between persons by semicolons and puts a comma instead of a white space between last and first names:

(not tested, so be careful ;))

Code: Select all

Program NewScript;
uses
  StringUtils1;
var
  s: string;
  i, p: Integer;
  List: TStringList;
begin
  if List = nil then
    List := TStringList.Create;
  List.Text := StringReplace(GetField(fieldDirector), ',', #13#10);
  for i := 0 to List.Count - 1 do
  begin
    s := Trim(List.GetString(i));
    p := LastPos(' ', s);
    if p > 0 then
    begin
      s := Copy(s, p + 1, Length(s)) + ', ' + Copy(s, 1, p - 1);
    end;
    List.SetString(i, ' ' + s);
  end;
  s := Trim(StringReplace(List.Text, #13#10, ';'));
  if StrGet(s, Length(s)) = ';' then
    Delete(s, Length(s), 1);
  SetField(fieldDirector, s);
end.
Of course, you can't run this script more than once for a movie for a field: else it would mess up the names already processed.

Note: "p" was obtained with the Pos function. I replaced it by the LastPos function, I didn't do that directly yesterday as I was not sure that it existed, but it seems that I added that function in "StringUtils1" unit, that makes the work of this script easier.

Posted: 2009-01-22 13:59:52
by Melmoth
:grinking:
Perfect, that's exactly what I needed! Now my books are in "last name, first name order", even double-barrelled names work if hyphenated...

Thanks a lot!!!

Melmoth