#1 2012-09-10 12:50

avpeer
Member
Registered: 2012-09-10
Posts: 2

Capitalize the first letter from each word between brackets

Hi,

Started using this program with great pleasure but i have a question. How can i capitalize the first letter from each word between brackets?

Ex.

From:

I can only imagine (feat. chris brown and lil wayne)

To:

I can only imagine (Feat. Chris Brown And Lil Wayne)

Thanks for the help.

Last edited by avpeer (2012-09-10 13:13)

Offline

#2 2012-09-10 16:11

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,108

Re: Capitalize the first letter from each word between brackets

Hi and welcome.


From:
I can only imagine (feat. chris brown and lil wayne).ext
To:
I can only imagine (Feat. Chris Brown And Lil Wayne).ext




Yes, unfortunately there is no easy solution.
The Case Rule could have an "apply to that part"-regex option, but the developer has not much time.



But we can use an PascalScript for such issues.

Read our wiki how to use an PascalScript > http://www.den4b.com/wiki/ReNamer:Rules:PascalScript
(thanks to the wiki maintainers)


and then use e.g. this code:

var
  iPOS:integer;
  Base, Part1, Part2:WideString;
 
begin
  Base := WideExtractBaseName(FileName);

  iPOS  := WidePos('(', Base);
  Part1 := WideCopy(Base, 1   , iPOS -1);
  Part2 := WideCopy(Base, iPOS, 999    );

  FileName := Part1 
            + WideCaseCapitalize(Part2)
            + WideExtractFileExt(FileName);
end.

Now i have seen i had not exactly follow your wish "between brackets", because this script just takes all
from the first open '(' parenthesis to the end. but since it works for your provided example file i guess it is ok?
If not use this code:

var
  Parts: TStringsArray;
  
begin
  // match the string between the first found parenthesis:
  // Example: I can (feat. chris brown) (remix).ext
  
  // The RegEx splits the base name into:
  // Part1: "I can "
  // Part2: "(feat. chris brown)"
  // Part3: " (remix)" //if any part3
  Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+?)(\(.+?\))(.*)', FALSE);
  If (Length(Parts) <=0) then exit;

  //Part2 is case changed:
  Parts[1] := WideCaseCapitalize(Parts[1]);
  
  //New Name:
  FileName := Parts[0] + Parts[1] + Parts[2] + WideExtractFileExt(FileName);
 end.

In ReNamer click at [Preview]  and see how it works for you. If it works please help Denis too.

Last edited by Stefan (2012-09-10 16:28)


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#3 2012-09-10 18:07

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Capitalize the first letter from each word between brackets

Maybe this is not very relevant but I made a modification to search recursively for brackets in the last part of the string.

Just for fun:

function CapitalizeBetweenBrackets(S: WideString): WideString;
var Parts: TStringsArray;
begin
  // Divide the string in parts
  Parts := SubMatchesRegEx(S, '^(.*?)(\(.+?\))(.*)$', false);
  
  if (length(Parts) = 3) then
  begin
    // Capitalize the part between brackets
    Parts[1] := WideCaseCapitalize(Parts[1]);

    // Check again for brackets in the third part.
    if (Parts[2] <> '') then
      Parts[2] := CapitalizeBetweenBrackets(Parts[2]);
    
    // Join the parts
    Result := Parts[0] + Parts[1] + Parts[2];
  end
  else
  begin
    // If no brackets found return the string unchanged
    Result := S;
  end;
end;

begin
  FileName := CapitalizeBetweenBrackets(FileName);
end.

If this software has helped you, consider getting your pro version. :)

Offline

#4 2012-09-11 09:03

avpeer
Member
Registered: 2012-09-10
Posts: 2

Re: Capitalize the first letter from each word between brackets

Thanks a lot, it's working like a charm!!!!

Offline

Board footer

Powered by FluxBB