You are not logged in.
How can i split FILENAME into parts at an given sign with PascalScript?
i.e.
we have FILENAME "some file name.txt"
and i want to split it with something like x := SPlit(FileName, ' ')
to get
x[0] some
x[1] file
x[2] name
Pascals 'Wrap' give error in PascalScript.
I searched and found some code but nothing work with PascalScript.
// from http://www.delphipraxis.net/topic27196_splitfunktion.html
function Split(const fText: String; const fSep: Char; fTrim: Boolean=false; fQuotes: Boolean=false):TStringList;
xxxxyyyyzzzz
end;
//========
var
part: array of string;
begin
part := Split(FileName, ' ');
FileName := part[2];
end
Last edited by Stefan (2007-11-06 19:08)
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
Have a look at the Help document for PascalScript rule. It lists all of the available functions/procedures and types (excluding basic data types like integers, strings, etc). I didn't register any classes like TStringList, because it means redeclaring all these classes/units for PascalScript. I prefer to keep all of the functionality to functions for several reasons, e.g. safer, more consistent, much less overhead, etc.
Anyway, you need to use this function below:
function WideSplitString(const Input, Delimiter: WideString): TStringsArray;
var
I: Integer;
Parts: TStringsArray;
begin
Parts := WideSplitString(FilePath, '\');
for I:=0 to Length(Parts)-1 do
begin
// access each part via Parts[i]
end;
end.
Offline
> Have a look at the Help document for PascalScript rule.
I swear i have used the search function But obviously i am not able to do an correct search. Today i see it too.
> I didn't register any classes like TStringList,
I even not know what TStringList is, i have copied just the code.
> I prefer to keep all of the functionality to functions
So you wrote functions in Pascal and provide this us inside the ReNamer.exe?
> Anyway, you need to use this function below:
Thank you.
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 it works:
// Swaps FileName-parts at minus-sign.pas
const
// sign where to split the file name:
// f. ex. "Artist - Song.mp2" split at ' - '
SplitSign = ' - ';
var
Parts: TStringsArray;
begin
// split the filename at '-' into parts:
Parts := WideSplitString(WideExtractBaseName(FileName), SplitSign);
// Note: parts are numbered from 0 on: 0, 1, 2, 3...
// build your new name:
// Here: second part[1] first, then SpaceMinusSpace, then the first part[0]:
FileName := Parts[1] + ' - ' + Parts[0] + WideExtractFileExt(FileName);
end.
Spelling and grammar corrections allowed.
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
For this task, you can also use a simple RegEx rule...
Expression: (.*) - (.*)
Replace: $2 - $1
Offline
I know and i know that you know
But average user can't remember RegEx so they could just select an Script to do the same (and i imaging more to do with it)
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