You are not logged in.
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
Hi joacim
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
woow! it works just perfect.
You saved my day!
Thnx!
:yes:
Offline
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
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
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.mp3Is 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
Thanks Joacim
That worked like a charm
Have a good day
Offline
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
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
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.
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