#1 2019-09-16 11:24

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

PascalScript: DeleteBlock, DeleteTill, CopyBlock, CopyTill

To avoid the use of RegEx and additional in-between-use of "Pos()" function for to make it more easier for the average user,
I want to suggest two or four new PascalScript functions (http://www.den4b.com/wiki/ReNamer:Pasca … :Functions):


Already existent:
function myIndex:= WidePos(const SubStr, S: WideString): Integer;    
Find and occurrence of SubStr in S. Returns the position of first occurrence, or 0 if nothing was found.

procedure Delete(var S: String; Index, Count: Integer);       
Deletes COUNT characters from the string S, starting from position Index.

New suggestion:
procedure DeleteBlock(var S: String; Amount: Integer);
Delete from left an BLOCK of any combination of chars and signs until next SPACE. Amount: how many blocks to delete.

procedure DeleteTill(var S: String; Find: String);               
Delete from left an BLOCK of any combination of chars and signs until found next "FIND" (e.g.: space, hyphen, underscore, dot,...).

- - -

Already existent:
function WideCopy(const S: WideString; Index, Count: Integer): WideString;
Returns COUNT characters from S, starting at position Index.

New suggestion:
function WideCopyBlock(S: String; Amount: Integer): WideString;     
Copy from left an BLOCK of any combination of chars and signs until next SPACE. Amount: how many blocks to copy.

function WideCopyTill(S: String; Find: String): WideString;             
Copy from left an BLOCK of any combination of chars and signs until found next "FIND" (e.g.: space, hyphen, underscore, dot,...).

- - -

I would suggest to remove the "FIND" sign and THEN next every trailing space(s) automatically on default for the functions.
Me think it's more easier to add need/wanted signs again on or own than using another function to trim them.
((( WideTrimCharsRight(const S, CharsToTrim: WideString): WideString; )))


- - -

Usage example:
on FileName = "Artist - Song.mp5"

OldBase := WideExtractBaseName(FileName);
FirstPart := WideCopyTill(OldBase,' - ');
DeleteTill(OldBase,' - ');
FileName := OldBase + ' - ' + FirstPart + WideExtractFileExt(FileName);


Another example:
OldName := FileName;
DeleteBlock(OldName,1);
FileName := 'New Prefix ' + OldName;




I also want to suggest an Boolean parameter for the copy() function to copy AND delete in one go:
OldBase := WideExtractBaseName(FileName);
FirstPart := WideCopyTill(OldBase,' - ', Del=true);
FileName := OldBase + ' - ' + FirstPart + WideExtractFileExt(FileName);




Thanks for any considering big_smile

And yes, the *Till() functions with a space as FIND will include the *Block() functions feature (nearly) too,
...but that was just my start and since I find that useful I decided to let that suggestion too.


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

Board footer

Powered by FluxBB