This evening i had a little bit of time to see what is possible and how.
I came up with this algorithm:
(test code, real script will follow...i hope)
Code: Select all
// test input:
$file = "Designer - Notes - Two-in-one - Yellow.2.4";
// user settings:
$Pattern = " - "; // the pattern to split the string at
$StartPattern = "SOL"; // "SOL", 1, 2, 3,... Give me the part after pattern no.1, or 2, or start from "StartOfLine"
$StartPosAdj = 3; // 1, 2, 3,... Remove additional signs (trim)
$EndPattern = 3; // "EOL", 2, 3, 4,... Till the part before pattern no.3, or 4, or till "EndOfLine"
$EndPosAdj = ; // 1, 2, 3,... Remove additional signs (trim)
// the code, don't modify:
if ($StartPattern=="SOL"){
$StartPos = 0;}
else{
$loop = 1;
$PatternPos=1;
while($loop <= $StartPattern){
$StartPos = strpos($file, $Pattern, $PatternPos+1);
$PatternPos = $StartPos;
incr $loop;
}
$StartPos = $StartPos + $StartPosAdj;
}
if ($EndPattern=="EOL"){
$EndPos = "";
$namelen = "";}
else{
$loop = 1;
$PatternPos=1;
while($loop <= $EndPattern){
$EndPos = strpos($file, $Pattern, $PatternPos+1);
$PatternPos = $EndPos;
incr $loop;
}
$EndPos = $EndPos - $EndPosAdj;
$namelen = $EndPos-$StartPos;
}
$newname = substr($file, $StartPos, $namelen);
msg $file<crlf>StartPos: $StartPos<crlf>EndPos: $EndPos<crlf>#$newname#;
Results examples:
Code: Select all
$file = "Designer - Notes - Two-in-one - Yellow.2.4";
// user settings:
$Pattern = " - "; // the pattern to split the string at
$StartPattern = "SOL"; // "SOL", 1, 2, 3,... Give me the part after pattern no.1, or 2, or start from "StartOfLine"
$StartPosAdj = 3; // 1, 2, 3,... Remove additional signs (trim)
$EndPattern = 3; // "EOL", 2, 3, 4,... Till the part after pattern no.3, or 4, or till "EndOfLine"
$EndPosAdj = ; // 1, 2, 3,... Remove additional signs (trim)
---------------------------
XYplorer
---------------------------
Designer - Notes - Two-in-one - Yellow.2.4
StartPos: 0
EndPos: 29
#Designer - Notes - Two-in-one#
---------------------------
OK
---------------------------
Code: Select all
// user settings:
$Pattern = " - "; // the pattern to split the string at
$StartPattern = 1; // "SOL", 1, 2, 3,... Give me the part after pattern no.1, or 2, or start from "StartOfLine"
$StartPosAdj = 3; // 1, 2, 3,... Remove additional signs (trim)
$EndPattern = 2; // "EOL", 2, 3, 4,... Till the part before pattern no.3, or 4, or till "EndOfLine"
$EndPosAdj = ; // 1, 2, 3,... Remove additional signs (trim)
---------------------------
XYplorer
---------------------------
Designer - Notes - Two-in-one - Yellow.2.4
StartPos: 11
EndPos: 16
#Notes#
---------------------------
OK
---------------------------
Code: Select all
// user settings:
$Pattern = " - "; // the pattern to split the string at
$StartPattern = 2; // "SOL", 1, 2, 3,... Give me the part after pattern no.1, or 2, or start from "StartOfLine"
$StartPosAdj = 3; // 1, 2, 3,... Remove additional signs (trim)
$EndPattern = "EOL"; // "EOL", 2, 3, 4,... Till the part before pattern no.3, or 4, or till "EndOfLine"
$EndPosAdj = ; // 1, 2, 3,... Remove additional signs (trim)
---------------------------
XYplorer
---------------------------
Designer - Notes - Two-in-one - Yellow.2.4
StartPos: 19
EndPos:
#Two-in-one - Yellow.2.4#
---------------------------
OK
---------------------------
Code: Select all
// user settings:
$Pattern = " - "; // the pattern to split the string at
$StartPattern = 2; // "SOL", 1, 2, 3,... Give me the part after pattern no.1, or 2, or start from "StartOfLine"
$StartPosAdj = 3; // 1, 2, 3,... Remove additional signs (trim)
$EndPattern = 3; // "EOL", 2, 3, 4,... Till the part before pattern no.3, or 4, or till "EndOfLine"
$EndPosAdj = ; // 1, 2, 3,... Remove additional signs (trim)
---------------------------
XYplorer
---------------------------
Designer - Notes - Two-in-one - Yellow.2.4
StartPos: 19
EndPos: 29
#Two-in-one#
---------------------------
OK
---------------------------
And no, i don't like how the forum look-a-like since last week. And i don't like this small, scrollable code boxes.
.