Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/25/2013 in all areas

  1. I've started a thread or two since Jan 2009 about better documenting the == operator. I've probably also posted in a dozen other threads trying to assist members asking this same question. The docs used to say only that "=" was case-sensitive and that "==" was case-insensitive. The wording was expanded a little, but I think it still lacks clarity. Stating that "This operator should only be used for string comparisons that need to be case sensitive" is incorrect as the == operator is very useful when trying to compare any of the following: - A numeric zero: 0 - A string zero: "0" or Chr(48) - An empty string: "" - A null character: Chr(0) - Boolean False The = operator will accept any 2 of the above values as being equivalent. The == operator can discern between all 5 entities above, accepting no 2 as being equal. I've found the operator useful to differentiate between an empty string and a zero more than once. That's not really a comparison that falls under the "case-dependant string comparison" umbrella.
    1 point
  2. Gibbo

    _PathSplitRegEx

    Recently I had the need to split paths like _PathSplit outside of AutoIt. Regular expressions seemed to be the way to go and it was fun to learn a bit more about their power. I backported it to AutoIt and now use it instead of _PathSplit. This should match any combination of: servershare[$] | Drive path filename .extentionSome caveats: It only returns an array (returning strings via byref aswell seemed a tad overkill / messy) The Drive letter retains its trailing "" NOT the path (this seemed more sane as the path should be relative not anchored to the root of the drive) - Found that this was not so good for things like "C:" as the path shoud be set to "" not nothing ; #FUNCTION# ==================================================================================================================== ; Name...........: _PathSplitRegEx ; Description ...: Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing. ; Syntax.........: _PathSplitRegEx($sPath) ; Parameters ....: $sPath - The path to be split (Can contain a UNC server or drive letter) ; Return values .: Success - Returns an array with 5 elements where 0 = original path, 1 = drive, 2 = directory, 3 = filename, 4 = extension ; Author ........: Gibbo ; Modified.......: ; Remarks .......: This function does not take a command line string. It works on paths, not paths with arguments. ; This differs from _PathSplit in that the drive letter or servershare retains the "" not the path ; RegEx Built using examples from "Regular Expressions Cookbook (O’Reilly Media, 2009)" ; Related .......: _PathSplit, _PathFull, _PathMake ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _PathSplitRegEx($sPath) if $sPath="" then Return SetError(1,0,"") Local Const $rPathSplit = '^(?i)([a-z]:|[a-z0-9_.$]+[a-z0-9_.]+$?)?((?:[^/:*?"<>|rn]+)*)?([^/:*?"<>|rn.]*)((?:.[^./:*?"<>|rn]+)?)$' Local $aResult = StringRegExp($sPath, $rPathSplit, 2) Switch @error Case 0 Return $aResult Case 1 Return SetError(2, 0, "") Case 2 ;This should never happen! EndSwitch EndFunc ;==>_PathSplitRegExAnyhow, I hope someone else finds this useful Edit: @ScriptFullPath replaced with the parameter $sPath - Thanks czardas. Should have reread before posting. Edit2: Changed regex to move the trailing "" from the "root" to the begining of the path. Edit3: Edit destroyed the regex (why??) added below as well in plain code tags just in case it happens again: Local Const $rPathSplit = '^(?i)([a-z]:|[a-z0-9_.$]+[a-z0-9_.]+$?)?((?:[^/:*?"<>|rn]+)*)?([^/:*?"<>|rn.]*)((?:.[^./:*?"<>|rn]+)?)$'
    1 point
×
×
  • Create New...