#1 2006-05-19 21:52

joacim
Member
Registered: 2006-05-19
Posts: 2

Insert blank space between lowercase and uppercase

Hi

Is it possible to insert a "blank space" between a lowercase and a uppercase i.e

HiMyNameIsJoacim -> Hi My Name Is Joacim

thnx

joacim

Offline

#2 2006-05-20 04:46

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

Re: Insert blank space between lowercase and uppercase

Hi joacim smile

Yes, it is possible, by using PascalScript rule, and here is the code:

function IsUpperCase(C: Char): Boolean;
begin
  Result := C = UpperCase(C);
end;

function IsLowerCase(C: Char): Boolean;
begin
  Result := C = LowerCase(C);
end;

function IsLetter(C: Char): Boolean;
begin
  Result := UpperCase(C) <> LowerCase(C);
end;

var
  I, Len: Integer;
begin
  Len := Length(FileName);
  for I:=Len downto 2 do
    if IsLetter(FileName[i]) then
    if IsUpperCase(FileName[i]) and 
       IsLowerCase(FileName[I-1])
    then Insert(' ', FileName, I); 
end.

Offline

#3 2006-05-20 09:42

joacim
Member
Registered: 2006-05-19
Posts: 2

Re: Insert blank space between lowercase and uppercase

woow! it works just perfect.

You saved my day! yikes

Thnx!

:yes:

Offline

#4 2008-02-16 15:42

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

Re: Insert blank space between lowercase and uppercase

Just to update:

Because ReNamer went into full Unicode support since v4.00, the code posted above raises "Type Mismatch" error when used on latest versions. This is because the type of the FileName variable changed to WideString, which makes the type of each character FileName[i] type WideChar, instead of the expected Char type by the used functions in the script.

For current version of ReNamer v5.20, the code below will do the same job:

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.

Offline

#5 2008-09-09 22:52

Tom221
Member
Registered: 2008-09-09
Posts: 5

Re: Insert blank space between lowercase and uppercase

I tried this and it works to a point. If you have the words I or A it does not separate them.
For Example: TheEverlyBrothers - AllIHaveToDoIsDream.mp3 becomes The Everly Brothers - All IHave To Do Is Dream.mp3

Is there a way to fix this?
Thank you

Offline

#6 2008-09-10 08:10

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

Re: Insert blank space between lowercase and uppercase

Tom221 wrote:

I tried this and it works to a point. If you have the words I or A it does not separate them.
For Example: TheEverlyBrothers - AllIHaveToDoIsDream.mp3 becomes The Everly Brothers - All IHave To Do Is Dream.mp3

Is there a way to fix this?
Thank you

Not easy since ABBA would become A B B A then ;-)
We would need an array of exceptions for that issue (i think)

I have tried to modify the script from Denis to solve your current problem,
but as i said, this is no general solution :


// http://www.den4b.com/forum/viewtopic.php?id=14
// Is it possible to insert a "blank space" between a lowercase and a uppercase i.e
// HiMyNameIsJoacim -> Hi My Name Is Joacim
//update 21.Feb.2008 for ReNamer > 4
//update 09.Sep..2008 for Tom221 issue with "IHave"
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)
else
     if IsWideCharAlpha(FileName[i]) then
       if IsWideCharUpper(FileName[i]) and 
          IsWideCharUpper(FileName[i-1])
          then WideInsert(Separator, FileName, I);
end.

I have simply added
    
else
     if IsWideCharAlpha(FileName[i]) then
       if IsWideCharUpper(FileName[i]) and
          IsWideCharUpper(FileName[i-1]);

I have also tried with
IsWideCharBlank(FileName[i-2])
but no success due i have no time yet and i am not good in coding.

Last edited by Stefan (2008-09-10 08:11)


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

#7 2008-09-10 15:07

Tom221
Member
Registered: 2008-09-09
Posts: 5

Re: Insert blank space between lowercase and uppercase

Thanks Joacim
That worked like a charm
Have a good day

Offline

#8 2008-09-14 13:32

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

Re: Insert blank space between lowercase and uppercase

The previous code by Stefan can be simplified into this:

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

This will put a space in front of ALL CAPITAL letters.

Offline

#9 2008-09-14 14:36

Tom221
Member
Registered: 2008-09-09
Posts: 5

Re: Insert blank space between lowercase and uppercase

Thanks for your reply. Your code would be great if that was what I wanted to do.
I wanted to separate words in a audio file name and the above code did this but left behind a problem with, for example, "IHave" would not separate. The extra code by Joacim did this fine.
I will keep your code in mind if that situation comes up.
Thanks again

Offline

#10 2015-10-02 04:55

lanceru
Member
Registered: 2015-09-29
Posts: 10

Re: Insert blank space between lowercase and uppercase

Thanks for the Pascal code den4b.

I had a bit more similar but complex question from a different thread that utilized RegExp. It seems Pascal may be the way to go.


lanceru wrote:

What if I only want to add a hyphen, before only the 2nd capitalized word?
Or,
At only the 3rd capitalized word?
Or,
For the 2nd and 3rd capitalized words (specify range)?

I have a file named:
JimCanson_DepartmentManufacture,

and then transform it to:
Jim_Canson_DepartmentManfacture, not Jim_Canson_Department_Manufacture

In any case I'm mainly just interested in the first question.
"What if I only want to add a hyphen, before only the 2nd capitalized word?"

The closes I can come up with

const
  Separator = '_';
var
  I: Integer;
begin
  for I:=2 to 100 do
    if IsWideCharAlpha(FileName[i]) then
      if IsWideCharUpper(FileName[i]) and IsWideCharLower(FileName[I+1])
      then WideInsert(Separator, FileName, I);
      // break; this results in an error message.
end.            

I need a way to terminate the loop.

Last edited by lanceru (2015-10-02 05:10)

Offline

Board footer

Powered by FluxBB