#1 2007-02-17 23:47

jesus64
Member
Registered: 2007-02-17
Posts: 3

Run Rule Case "First Letter Capital" in a position determined

Hello Denis,
First, congratulations for this excelent program! smile

And now I have one question: roll

I want to rename a portion of a file with the rule Case: "First Letter Capital". I need rename starting in a position determined.

For example:

Growing Pains - 1x01 - This Is The First Episode [dvdrip]

I want to rename only the string "This Is The First Episode" with "This is the first episode":

Growing Pains - 1x01 - This is the first episode [dvdrip]

I tried with Pascal, but only know the Lowercase or Upercase functions...

Please, help me!:rolleyes:

Thanks for this good program.

Jesus.

Offline

#2 2007-02-18 12:11

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Run Rule Case "First Letter Capital" in a position determined

Hey there!

It's possible with pascal script. I can write it for you, just tell me what exactly determines the position from which you want to set first letter capital. Is it always after second "-" (dash) symbol?

Offline

#3 2007-02-18 14:08

jesus64
Member
Registered: 2007-02-17
Posts: 3

Re: Run Rule Case "First Letter Capital" in a position determined

Hi Denis!

Yes, the second dash "-" is the first position for set "First letter capital", and the symbol "[" it's the end position, like the example.

Thanks for the quickly reponse. smile

Regards.;)

Offline

#4 2007-02-18 16:15

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Run Rule Case "First Letter Capital" in a position determined

Here you go.. smile

Script will capitalize the first letter and put everything else in lower case for fragment of filename which is between second dash and first opening square bracket (after the second dash). If bracket not found, it will lower case for the rest of the filename after the second dash. Make sure you use the latest version (v4.50 is required).

var
  I, PosStart, PosEnd: Integer;
  
begin
  PosStart := WidePos('-', FileName);
  if PosStart <= 0 then Exit;
  PosStart := WidePosEx('-', FileName, PosStart+1);
  if PosStart <= 0 then Exit;
  PosEnd := WidePosEx('[', FileName, PosStart+1);
  if PosEnd <= 0 then PosEnd := WideLength(FileName);
  
  FileName := WideCopy(FileName, 1, PosStart) +
    WideLowerCase(WideCopy(FileName, PosStart+1, PosEnd-PosStart-1)) +
    WideCopy(FileName, PosEnd, WideLength(FileName)-PosEnd+1);
  for I:=PosStart to PosEnd do
    if IsWideCharAlpha(FileName[i]) then
    begin
      FileName[i] := WideUpperCase(FileName[i])[1];
      Break;
    end;
end.

Offline

#5 2007-02-19 02:41

jesus64
Member
Registered: 2007-02-17
Posts: 3

Re: Run Rule Case "First Letter Capital" in a position determined

Thanks Denis, the script work perfectly smile

You are the number one! wink

Jesus.

Offline

#6 2008-02-28 08:56

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Run Rule Case "First Letter Capital" in a position determined

Hi Denis,
I've finally managed to write my first PascalScript. Well...not write to be accurate.. I've managed to modify existing script and made it to do what I want:-)
I needed it to Uppercase the part of filename after ']'.
And it does it:-)

But there is one thing I can't figure out in that code.
What [1] in the line:
      FileName[i] := WideUpperCase(FileName[i])[1];
does?
It seems to do some type conversion... But what and how?

var
  I, PosStart, PosEnd: Integer;
  
begin
  PosStart := WidePos(']', FileName);
  if PosStart <= 0 then Exit;

  PosEnd := WideLength(FileName);
  
  FileName := WideCopy(FileName, 1, PosStart) +
    WideLowerCase(WideCopy(FileName, PosStart+1, PosEnd-PosStart-1)) +
    WideCopy(FileName, PosEnd, WideLength(FileName)-PosEnd+1);
  for I:=PosStart to PosEnd do
    if IsWideCharAlpha(FileName[i]) then
    begin
      FileName[i] := WideUpperCase(FileName[i])[1];
      Break;
    end;
end.

Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#7 2008-03-04 21:32

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Run Rule Case "First Letter Capital" in a position determined

krtek, I'm glad that you are getting your skills onto scripts big_smile

First of all, there are two different types to represent text: String and WideString. First is for ANSI text (1 byte per character), and second is for UNICODE text (2 bytes per character). They both have same structure, where each character can be accessed by its index, i.e. [1], [2], ..., [N]. Note that in String and WideString first character has index 1, not like in arrays! Now, since there are 2 types for representing text, there must be 2 types for representing characters, so... String[i] -> Char, WideString[i] -> WideChar.

That was an introduction tongue

Now, look at the syntax of the WideUpperCase function:
function WideUpperCase(const S: WideString): WideString;

Complier can automatically convert character into string type, but not other way around.

So you can do FileName[i] := FileName[i] and FileName := FileName[i], but cannot do FileName[i] := FileName;

Back to the original problem....
* FileName[i] - gives us a character,
* WideUpperCase(FileName[i]) - gives use an upper case character AS STRING,
* WideUpperCase(FileName[i])[1] - gives use the first upper case character of that string,
* FileName[i] := WideUpperCase(FileName[i])[1] - puts each character into upper case.

I hope it clears up few things smile

Offline

#8 2008-03-08 07:33

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Run Rule Case "First Letter Capital" in a position determined

Thanks a lot, Denis!
It definitely cleared few things up for me smile
I had no idea that you can refer to index of string that is result of function without assigning that result to a variable. That really shortens notation. big_smile


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#9 2008-03-09 22:01

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Run Rule Case "First Letter Capital" in a position determined

To make your life even easier, I've added two helper functions:

function WideCharUpper(const WC: WideChar): WideChar;
function WideCharLower(const WC: WideChar): WideChar;

So now you don't need to do that [1] casting, just use:

FileName[i] := WideCharUpper(FileName[i]);

ReNamerBeta.zip big_smile

Offline

Board footer

Powered by FluxBB