topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday April 18, 2024, 2:13 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Help creating a custom script to modify format  (Read 4476 times)

asrjcb

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 16
    • View Profile
    • Donate to Member
Help creating a custom script to modify format
« on: February 24, 2015, 04:51 PM »
I'd like to take a file name with "-" or "_" in between words and replace them with normal spaces.  This is caused when I download files from Share Points.  But, only after the 2nd occurrence of the string in a standard document naming convention.

Examples:
I want to change "GEN-S-01-How-to-Make-a-Custom-Script" to "GEN-S-01 How to Make a Custom Script"
I want to change "GEN-S-01_How_to_Make_a_Custom_Script" to "GEN-S-01 How to Make a Custom Script"

I'd like to just type it in the Find and Replace, Find field in the Modify Format/Case tool versus making a Custom Script Tool (which I think would be way over my head).


I tried to fool around with regular expressions, but have no experience and failed.  Thanks in advance.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Help creating a custom script to modify format
« Reply #1 on: February 24, 2015, 05:16 PM »
ok this is a bit convoluted, but should work in CHS:

go to the search and replace tab and you will create 3 entries in this order:

First, a regex one:
Find: ^([^\-\+]+)([\-\_])([^\-\+]+)([\-\_])([^\-\+]+)(.*)$
Replace: $1DASHSEP$3DASHSEP$5$6

Next, a regex one:
Find: [\-\_]
for Replace put a single space

Lastly, a non regex (though shouldnt matter):
Find: DASHSEP
Replace: -


What this does: Changes the first two dashes (or underscores) into the word DASHSEP
Then Replaces all remaining dashes/underscores into spaces
Then puts back the first two dash/underscores with dashes (note that if the first two were an underscore they will change to dash).


screenshot:
Screenshot - 2_24_2015 , 5_15_45 PM.png

Note:
You might still be better off learning to use a simple scripts with CHS because that would allow you to tweak things like this and do more complicated stuff.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help creating a custom script to modify format
« Reply #2 on: February 25, 2015, 08:32 AM »
Ooh! That's a rather a nifty use of CHS, once again showing its potential in ways one might not have intuitively expected. I certainly hadn't really thought about doing something like that with it anyway. Thanks!
 :-* CHS  :-*

asrjcb

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 16
    • View Profile
    • Donate to Member
Re: Help creating a custom script to modify format
« Reply #3 on: February 25, 2015, 03:01 PM »
Wow mouser thanks, it worked perfectly.  I'm a huge fan and love Find and Run Robot and CHS.  Don't know what I'd do without them.  Thanks again.

spam spam bacon spam

  • Member
  • Joined in 2014
  • **
  • Posts: 20
    • View Profile
    • Donate to Member
Re: Help creating a custom script to modify format
« Reply #4 on: July 07, 2015, 06:00 PM »


Find: ^([^\-\+]+)([\-\_])([^\-\+]+)([\-\_])([^\-\+]+)(.*)$
Replace: $1DASHSEP$3DASHSEP$5$6

Find: DASHSEP
Replace: -

What this does: Changes the first two dashes (or underscores) into the word DASHSEP
Then puts back the first two dash/underscores with dashes (note that if the first two were an underscore they will change to dash).


Dude.

That was utterly genius!!

Well played, sir.  Well played.

~spammage