Multi Commander > Script

Title Case

<< < (2/3) > >>

Ulfhednar:
Thanks very much Mathias.  ;D  8)
I didn't realize I could use this array form in MS -

--- Code: ---@var $exceptionsArray[] = { "a", "an", "and", "any", "at", "from", "into", "of", "on", "or", "the", "to", };
--- End code ---

The function you have provided is very helpful in making me see the break-down of events & how MS can be used to run different tasks.  I will have to study/learn your style. 

Also I think I may have under-estimated MS & that that combined with my inexperience with ('modern') programming, causes trouble.
I have been looking at Java & C++ so I recognize these structures of code - just not well enough...! 
Better go & read those books I bought I guess ;)

OT Is it possible to create a StrRegExpReplace function for MS?  Or better to combine functions that are already there? 
I liked the idea of using StrRegExpFind to enumerate $<instance> & StrRegExpReplace to step through & replace each $<instance>.  Maybe that couldn't work in practice tho?

Mathias (Author):

--- Quote from: Ulfhednar on July 06, 2018, 18:31:42 ---
OT Is it possible to create a StrRegExpReplace function for MS?  Or better to combine functions that are already there? 
I liked the idea of using StrRegExpFind to enumerate $<instance> & StrRegExpReplace to step through & replace each $<instance>.  Maybe that couldn't work in practice tho?

--- End quote ---

It depends on what the bulit in regex engine support. RegEx is very got at complicating things to much too.  Maybe

Ulfhednar:
Thanks for the advice & info Mathias.
This is how I employed your function & it works well. I can see that it will be straightforward to expand on this for a number of other operations so I might actually learn how to use MS properly one day  :P ;)  It has (again) impressed on me that it is quite different from my school experience of Basic, this system feels like it contains a lot of macros in comparison.


--- Code: ---@var $exceptionsArray[] = { "a", "an", "and", "any", "at", "for", "from", "into", "of", "on", "or", "the", "to", };

function TitleCase($name)
{
   return  _TitleCase($name, " ");
}

function _TitleCase($name , $splitchar)
{

  @var $result = "";
  @var $parts = StrSplit($name , $splitchar); // space and - will split string
 
  @var $cnt = arrayCount( $parts );
  for( $n = 0; $n < $cnt ; $n++ )
  {
    @var $textPart = $parts[ $n ];
    // To Lower
    $textPart = StrToLower( $textPart );
 
    if( StrFind( $textPart , "-", 0 ) > 0)
    {
      // Becuse of recursive bug, $n is is overwriten
      $oldN = $n;
      $textPart = _TitleCase($textPart , "-");
      $n = $oldN;
    }

    if( arrayFind( $exceptionsArray, $textPart ) == -1)
    {
    // Uppser case on first
    $textPart[0] = StrToUpper( $textPart[0] );
    }

    if( StrLen( $result ) > 0 )
$result += $splitchar;

    $result += $textPart;
  }
  return $result;
}

 
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $NameA = PathGetNamePart( $arr );
@var $newText = TitleCase($NameA);
@var $i = 0;


for( $i = 0; $i < $items; $i++ )


{
RenameFile( $arr, $newText, "RENAME_RO" );
}
--- End code ---


EDIT
If I select multiple files it only runs on the first file... is this the recurse bug or is my recurse instruction bad... thought I had that one OK  :-\ ???

Mathias (Author):

--- Quote from: Ulfhednar on July 07, 2018, 16:08:20 ---
--- Code: ---
@var $arr = GetSourceSelectedPaths();
@var $NameA = PathGetNamePart( $arr );
@var $newText = TitleCase($NameA);
@var $i = 0;

 for ( $i = 0; $i < arrayCount( $arr ); $i++ )

{
RenameFile( $arr, $newText, "RENAME_RO" );
}
--- End code ---

--- End quote ---

Ehh what are you doing ?? that can't work
$arr is a list of files.  and a single file..
and then you take all the items in the array and rename everything to the same name  ?
Hm No not every item, you send RenameFile the complete array if path. not a specific item in the list

Ulfhednar:
OK I'm incorrectly thinking that because

--- Code: ---for( $n = 0; $n < $items; $n++ )
--- End code ---
works for multiple files - it will call the same thing ($arr) in 2 different ways --- which it won't  :o

I need to differentiate...  Thank you Mathias, I will try again & stop destroying your weekend now !   :D

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version