weaponx Posted July 5, 2007 Share Posted July 5, 2007 If I have an array called $ARRAY why cant I access the last element using $ARRAY[-1] or the second to last element using $ARRAY[-2] I have this 2 line code to retrieve the filename from a url but I want to do it in one line: $A = StringSplit($URL, "/") $FILENAME = $A[$A[0]] like $FILENAME = StringSplit($URL, "/")[-1] Link to comment Share on other sites More sharing options...
randallc Posted July 5, 2007 Share Posted July 5, 2007 Hi, try? local $URL="http://hotmail.com",$A = StringSplit($URL, "/"),$b=ConsoleWrite($A[UBound($A)-1]&@LF) Best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 5, 2007 Moderators Share Posted July 5, 2007 (edited) If I have an array called $ARRAY why cant I access the last element using $ARRAY[-1] or the second to last element using $ARRAY[-2]Personally, it wouldn't make much sense to me if it were. I have this 2 line code to retrieve the filename from a url but I want to do it in one line: $A = StringSplit($URL, "/") $FILENAME = $A[$A[0]] like $FILENAME = StringSplit($URL, "/")[-1]What difference does it make if you do it on 1 line or 2? With a little creativity you could probably solve your issue on your own though? $URL = "http://www.autoitscript.com/forum/index.php?act=Post&CODE=02&f=2&t=48900&qpid=368176" $FILENAME = _StringSplitEx($URL, '/', 0, -1) MsgBox(0, '', $FILENAME) Func _StringSplitEx($sString, $vDelim, $iFlag = 0, $nUBound = -1) Local $aSplit = StringSplit($sString, $vDelim, $iFlag) If $nUBound > -1 Then Return $aSplit[$nUBound] Return $aSplit[($aSplit[0] + $nUBound] EndFuncoÝ÷ ØGb´v¶âÆØ^~éܶ*'¶é¨ëÇ°+-áÝaz¼ÊÚqÊ&¦X¬Z·*.Á©í¢z®¢Ú'z«¨¶X§{ .Ù÷öׯzx§¾oy©Ú®¶²jëh×6$URL = "http://www.autoitscript.com/forum/index.php?act=Post&CODE=02&f=2&t=48900&qpid=368176" $FILENAME = StringTrimLeft($URL, StringInStr($URL, '/', 0, -1) MsgBox(0, '', $FILENAME) Edited July 5, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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