Page 1 of 1

splitting words

Posted: 27 Mar 2011 01:12
by Wanda
now and then i receive from colleagues files and lists which contains names when it comes to files or words in text lists like the following: KenRobinson-DoSchoolsKillCreativity?

how do I convert that into "Ken Robinson - Do Schools Kill Creativity?" both on files and in source documents?

Re: splitting words

Posted: 27 Mar 2011 04:45
by nas8e9
Wanda wrote:now and then i receive from colleagues files and lists which contains names when it comes to files or words in text lists like the following: KenRobinson-DoSchoolsKillCreativity?

how do I convert that into "Ken Robinson - Do Schools Kill Creativity?" both on files and in source documents?
That sounds like a job for regular expressions, which I can't help you with unfortunately; other forum members do know about it. By using those, XYplorer should be able to rename the files as you want them.

As for the content of files, it may be possible to script something in XYplorer, but a much more robust way would be to use a text editor like Notepad++ (freeware) which supports replacing with regular expressions; the same expression as used by XYplorer should be usable.

Hope this helps (somewhat... :)).

Re: splitting words

Posted: 27 Mar 2011 10:17
by Stefan
Hi Wanda, here are some ideas for you:
Wanda wrote: like the following: KenRobinson-DoSchoolsKillCreativity?

how do I convert that into "Ken Robinson - Do Schools Kill Creativity?"
An RegEx could look like this:

Space between lower upper case chars regex

Code: Select all

$IN = "KenRobinson-DoSchoolsKillCreativity";
//  TO Ken Robinson - Do Schools Kill Creativity

 //-------------------------------------------------------------------
 $OUT=$IN;
  while($Infinity < 99)
  {
    $OUT = regexreplace( $OUT, "(.+?[a-z])([A-Z].+)", "$1 $2", 1);

    //if there is nothing modified, then regexreplace() returns just the input
    //so if current the same as the last all is done and we can break:
      if ($last==$OUT){break;}
      $last=$OUT;

   $Infinity++;
  }
 //-------------------------------------------------------------------
   $OUT = replace($OUT, "-", " - ");
 //-------------------------------------------------------------------
  msg $OUT;


both on files
To rename file see rename() scripting command.


and in source documents?
To replace in file content an possible code could look like:
(but perhaps you already know the line containing the string then you didn't need an loop)


NOTE be sure to not replace binary or W0rd D0cs, and always test with copies of real files!!!

Modify file content lines search replace.xys

Code: Select all

// === User settings===
$file = "c:\temp\xyvbs.vbs";
  $FIND = "Wshell";
  $REPL = "WS";


// === code ===
   //read whole file into var:
   $content = readfile($file);

   //get amount of parts of file, delimitered by an newline, a.k.a Lines count:
   $lines = gettoken($content, "count", "<crlf>");

   $OUT="";
   $i=1;

   //loop over all lines
   while($i <= $lines)
   {
     $line = gettoken($content, $i, "<crlf>");
     if ($line==""){break;}

     if ( strpos($line, $FIND) > 0 )
     {
        $OUT = $OUT . replace($line, $FIND, $REPL);
     }
     else
     {
        $OUT = $OUT . $line;
     }

    if ($i < $lines){$OUT = $OUT  . "<crlf>";}

    $i++;
   }

//return output
   writefile( $file . "_modified.vbs", $OUT );
   msg "DONE";


------------------

@Don, wish:

writefile(filename, data, [on_exist], [mode])
on_exist
r: create new file/if existing: append suffix number "original_001.ext"


.

Re: splitting words

Posted: 27 Mar 2011 14:16
by admin
Stefan wrote:@Don, wish:

writefile(filename, data, [on_exist], [mode])
on_exist
r: create new file/if existing: append suffix number "original_001.ext"
Good, done.

Re: splitting words

Posted: 21 May 2011 18:42
by Wanda
thank you too. i can now deal with that boring files properly. thank you.

Re: splitting words

Posted: 07 Oct 2024 11:35
by sofia25
Thank you so much I can now handle those tedious files correctly.