#1 2008-02-15 22:59

DaveP
Member
Registered: 2008-02-15
Posts: 2

Insert - between words

How can I insert a - between names in a file?

From;
WRS0IC301705-BeltScrewWeighingSystem.doc

To:
WRS0IC301705-Belt-Screw-Weighing-System.doc

Offline

#2 2008-02-16 11:31

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

Re: Insert - between words

Hi Dave,

welcome to the forum big_smile

I would do that with regular expressions. cool

RegEx basics:
Search for any single lower case char       [a-z]
followed by
Search for any single upper case char      [A-Z]

Put () around this search to could refer to the search result later, so use:
Search for any single lower case char       ([a-z])
Search for any single upper case char      ([A-Z])

Later you can use  $n  to use the search result in your replacement.      'n' represents here the number of the n-th  ()-group.



Use this with ReNamer:
So add an new RULE > RegEx
Expression:        ([a-z])([A-Z])
Replace:            $1-$2

The lower and upper cased chars in the RegEx should be enough, but you have to check "[x] case-sensitive" too.


See an pic abou this:

I used here Replace:            $1 - $2

renamer520adddashbetweerg2.png

Last edited by Stefan (2008-02-16 11:34)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2008-02-16 11:44

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

Re: Insert - between words

To Denis.

this similar script

http://www.den4b.com/forum/viewtopic.php?id=14

gives me an Type mismatch

---------------------------
Error
---------------------------
Preview process has been terminated due to a critical error:

Pascal Script Compile:
[Line 21] Error: Type mismatch        ==>      if IsLetter(FileName[i]) then
---------------------------
OK   
---------------------------

(BTW: "Go to line" in Script-Rule works fine)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#4 2008-02-16 15:50

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Insert - between words

I posted an updated script and the explanation in that topic:
Insert blank space between lowercase and uppercase

So, DaveP, you can use the code from that topic, but simply change the separator, like this:

const
  Separator = '-';
var
  I: Integer;
begin
  for I:=WideLength(FileName) downto 2 do
    if IsWideCharAlpha(FileName[i]) then
      if IsWideCharUpper(FileName[i]) and 
         IsWideCharLower(FileName[I-1])
      then WideInsert(Separator, FileName, I); 
end.

It will work slighly faster than the RegEx rule, but RegEx rule might be more future proof.

Offline

#5 2008-02-19 06:15

DaveP
Member
Registered: 2008-02-15
Posts: 2

Re: Insert - between words

Fantastic!
Stefan's RegEx worked great.

Thanks a bunch!!!!!!!!!!:)

Offline

Board footer

Powered by FluxBB