tommytx Posted November 22, 2020 Share Posted November 22, 2020 Does anybody know of short quick simple command to find the last \ in the url... I know i can splitstring orcount them and figure it out.. but surely as nice as autoit is.. there must be something simple... Please. What i need is to grab the filename at the end of each line.. like colors.php So i could split at the \ and grab the last array item... but if anyone has something simpler I would appreciate it.. Thanks shorty\wp-content\plugins\IDXSEO\css\colors.php -> shorty\wp-content\plugins\IDXSEO\Geocoding\Geocron.php -> shorty\wp-content\plugins\IDXSEO\include\CRM.php -> shorty\wp-content\plugins\IDXSEO\include\FieldCategoriesFrontend.php Link to comment Share on other sites More sharing options...
tommytx Posted November 22, 2020 Author Share Posted November 22, 2020 OOPS! Sorry guys this was way simpler than i though in my mind.. I was not thinking about even though the array might have 20 items in some cases they only thing I need todo is simply get the last split... so I will use this.. but would still like to know if anything simpler than this is available.. Thanks.. $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" $cat = StringSplit($dog, "\") ConsoleWrite($cat[$cat[0]] & @CRLF) Prints - colors.php Link to comment Share on other sites More sharing options...
Danp2 Posted November 22, 2020 Share Posted November 22, 2020 There's also the _PathSplit function. You could use StringRegExpReplace as well. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
mikell Posted November 22, 2020 Share Posted November 22, 2020 Here it is as mentioned by Danp2 $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" $cat = StringRegExpReplace($dog, "^.+\\", "") Msgbox(0,"", $cat) Link to comment Share on other sites More sharing options...
Musashi Posted November 22, 2020 Share Posted November 22, 2020 Here all together : #include <File.au3> Local $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" Local $cat ; @tommytx : $cat = StringSplit($dog, "\") ConsoleWrite("1. <" & $cat[$cat[0]] & ">" & @CRLF) ; @mikell : $cat = StringRegExpReplace($dog, "^.+\\", "") ConsoleWrite("2. <" & $cat & ">" & @CRLF) ; with _PathSplit : Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" _PathSplit($dog, $sDrive, $sDir, $sFileName, $sExtension) ConsoleWrite("3. <" & $sFileName & $sExtension & ">" & @CRLF) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Gianni Posted November 22, 2020 Share Posted November 22, 2020 just another.., Local $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" MsgBox(0, '', StringMid($dog, StringInStr($dog, '\', 0, -1) + 1)) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted November 22, 2020 Share Posted November 22, 2020 5 hours ago, Musashi said: Here all together May I add another one $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" $cat = StringRegExp($dog, "[^\\]+$", 1) Msgbox(0,"", $cat[0]) Link to comment Share on other sites More sharing options...
Gianni Posted November 22, 2020 Share Posted November 22, 2020 is a small variation that saves 2 bytes allowed on my previous post? Local $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" MsgBox(0, '', StringTrimLeft($dog, StringInStr($dog, '\', 0, -1))) p.s. in versions that uses an array, if you want to save some bytes you can avoid using the $cat variable like this: Local $dog = "shorty\wp-content\plugins\IDXSEO\css\colors.php" Msgbox(0,"", StringRegExp($dog, "[^\\]+$", 1)[0]) GokAy and pseakins 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
pixelsearch Posted November 22, 2020 Share Posted November 22, 2020 52 minutes ago, Chimp said: Local $cat = StringTrimLeft($dog, StringInStr($dog, '\', 0, -1)) Chimp's code is exactly the one I'm using for a long time. When it comes to check the extension only, then '.' replaces '\' Local $sExt = StringTrimLeft($dog, StringInStr($dog, '.', 0, -1)) StringTrimRight is not forgotten, for example to get the path & name of an eventual ini file matching the script Local $sIniFile = StringTrimRight(@ScriptFullPath, 3) & "ini" This is endless... I guess habits are hard to change sometimes Link to comment Share on other sites More sharing options...
JockoDundee Posted November 22, 2020 Share Posted November 22, 2020 16 hours ago, Musashi said: Here all together : Update... The test results: tommytx : stmt length: 31 output:colors.php Time for 1000: 6.5914 each: 0.0066 mikell : stmt length: 31 output:colors.php Time for 1000: 6.5373 each: 0.0065 pathsplit: stmt length: 32 output:colors.php Time for 1000: 19.8721 each: 0.0199 chimp : stmt length: 43 output:colors.php Time for 1000: 4.4016 each: 0.0044 The code* tested: expandcollapse popup#include <File.au3> Global $p="shorty\wp-content\plugins\IDXSEO\css\colors.php" RunTest() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func tommytx($s) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $s=StringSplit($s,"\") Return $s[$s[0]] EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func mikell($s) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Return StringRegExp($s,"[^\\]+$",1)[0] EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func pathsplit($s) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Return _PathSplit($s,"","","",$s)[3]&$s EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func chimp($s) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Return StringTrimLeft($s,StringInStr($s,'\',0,-1)) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func RunTest() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ConsoleWrite("tommytx: length: 31 output:"& tommytx($p) &@CRLF) TimeIt(tommytx,1000) ConsoleWrite("mikell: length: 31 output:"& mikell($p) &@CRLF) TimeIt(mikell,1000) ConsoleWrite("pathsplit: length: 32 output:"& pathsplit($p) &@CRLF) TimeIt(pathsplit,1000) ConsoleWrite("chimp: length: 43 output:"& chimp($p) &@CRLF) TimeIt(chimp,1000) *code has been optimized for whitespace and identifiers - please respond with any further optimizations or objections to the current optimization. GokAy, Gianni and Musashi 2 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JockoDundee Posted November 23, 2020 Share Posted November 23, 2020 (edited) 4 hours ago, JockoDundee said: Update... ftr, I was unable to explicitly credit @pixelsearch for an algorithm, mainly because his username is areserved word built-in function Edited November 23, 2020 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Musashi Posted November 23, 2020 Share Posted November 23, 2020 (edited) On 11/22/2020 at 8:23 AM, Musashi said: Here all together : For the sake of completeness : This was meant as "all", which were mentioned up to this point . There are of course numerous ways to skin the cat, as shown hereafter. 8 hours ago, JockoDundee said: The test results: Nice addition to do a performance test. Edited November 23, 2020 by Musashi typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now