splitting words

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Wanda
Posts: 55
Joined: 08 Jan 2011 01:08

splitting words

Post 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?

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: splitting words

Post 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... :)).

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: splitting words

Post 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"


.

admin
Site Admin
Posts: 64915
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: splitting words

Post 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.

Wanda
Posts: 55
Joined: 08 Jan 2011 01:08

Re: splitting words

Post by Wanda »

thank you too. i can now deal with that boring files properly. thank you.

sofia25
Posts: 1
Joined: 07 Oct 2024 11:31
Location: UNITED STATES
Contact:

Re: splitting words

Post by sofia25 »

Thank you so much I can now handle those tedious files correctly.

Post Reply