Jump to content

_Stringbetween issue causing muddy results


 Share

Recommended Posts

  • Moderators

kylomas,

Thanks for that. I am glad you are not advocating action, because I do not intend taking any. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Taking care of EOLs would need _StringBetweenWithinMultilineText() and probably a new batch of fancy options :huh2:

Not generic enough and an ad-hoc RE is certainly in order.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi,

Please test this new version which has an additional parameter to determine the mode used:

#include <Array.au3>

$sTest = '<"100" tester="Things">Nowhere'

$aRet = _StringBetween_New($sTest, '"', '"') ; Default mode 0 - ending delimiter is not part of next search
_ArrayDisplay($aRet, "New - 8 style", Default, 8)

$aRet = _StringBetween_New($sTest, '"', '"', Default, 1) ; Mode 1 - ending delimiter is part of next search 
_ArrayDisplay($aRet, "New - 10 Style", Default, 8)

Func _StringBetween_New($sString, $sStart, $sEnd, $fCase = False, $iMode = 0)
    ; Set correct case sensitivity
    If $fCase = Default Then
        $fCase = False
    EndIf
    Local $sCase = "(?is)"
    If $fCase Then
        $sCase = "(?s)"
    EndIf

    ; Set mode
    If $iMode <> 1 Then $iMode = 0

    ; If you want data from beginning then replace blank start with beginning of string
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"

    ; If you want data from a start to an end then replace blank with end of string
    If $iMode Then
        $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"
    Else
        $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z"
    EndIf

    Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3)
    If @error Then Return SetError(1, 0, 0)
    Return $aReturn
EndFunc
Comments welcomed. :)

M23

 

 

@ Melba23

I'm studing and experimenting with your code about the use of the Ternary Operator

is this "other way" version equivalent to the above code or is there something wrong on using ternary operation like this?

It Seems That it works as well, but is not clear to me why the $sEnd variable is assigned Correctly only if used like in line number 29

while not assigned if I use the code as in the line number 30

#include <Array.au3>

$sTest = '<"100" tester="Things">Nowhere'

$aRet = _StringBetween_New($sTest, '"', '"') ; Default mode 0 - ending delimiter is not part of next search
_ArrayDisplay($aRet, "New - 8 style", Default, 8)

$aRet = _StringBetween_New($sTest, '"', '"', Default, 1) ; Mode 1 - ending delimiter is part of next search
_ArrayDisplay($aRet, "New - 10 Style", Default, 8)

Func _StringBetween_New($sString, $sStart, $sEnd, $fCase = False, $iMode = 0)
    ; Set correct case sensitivity
    Local $sCase
    (Default == $fCase) ? $sCase = "(?s)" : $sCase = "(?is)"

    ; If you want data from beginning then replace blank start with beginning of string
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"

    ; If you want data from a start to an end then replace blank with end of string
    $sEnd = $iMode ? ($sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z") : ($sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z")
;   $sXXX = $iMode ? ($sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z") : ($sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z")
    Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3)
    If @error Then Return SetError(1, 0, 0)
    Return $aReturn
EndFunc   ;==>_StringBetween_New

thanks

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Moderators

Pincopanco,

 

is there something wrong on using ternary operation like this?

Yes - code like that makes me think my eyes look like funkey's avatar! :D

Seriously, I prefer code that is easy to read (and debug) when you come back to it. Nested ternary operators are most definitely NOT that, so I would not recommend using them. :)

And the 2 lines #29 and #30 are identical - why do you think they produce different results? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

And the 2 lines #29 and #30 are identical - why do you think they produce different results? :huh:

M23

 

Because if line 30 is executed instead of line 29 the $sEnd variable (that is not used at the beginning of the line, was used another variable $sXXX instead) is not assigned correctly, while it should be (I think) by this part of code inside the brackets of the same line:

($sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z") : ($sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z")
Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

just wanted to make a comment on the original post (but had to take the cat to the vet so many replies have since shown up)

Since you are essentially telling you want the text between quotes ("") you are in fact getting what you asked for because if you look at the string (<"100" tester="Things">Nowhere') tester= is in fact in quotes (" tester=")

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

kaotkbliss,

That is what drove the last change to the function and caused this problem - which only occurs when the "start" and "end" strings are the same. My new version solves the dilemma by using a new parameter. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba,

If _StringBetween() means : "get what is included between the two borders of this box", one can hardly imagine that this could mean "get what is included between the border of this box and the border of the next one"
In such a case the func should have better been called _StringSplit_New()  :)

Link to comment
Share on other sites

  • Moderators

mikell,

I share your opinion and I was quite happy with the old version, but there were several requests for the new behaviour to be adopted. All I am doing now is offering the choice. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Was interested in the speed difference with nested ternary operators.

$sString = ''

Sleep(100)

$hTimer = TimerInit()
For $i = 1 To 100000
    If Random(0, 1, 1) Then ; If String.
        $sString = Random(0, 1, 1) ? 'True' : 'False'
    Else
        $sString = Random(0, 1, 1) ? True : False
    EndIf
Next
ConsoleWrite(TimerDiff($hTimer) & @CRLF)

$hTimer = TimerInit()
For $i = 1 To 100000
    ; Second random is if the return should be a string or not.
    $sString = Random(0, 1, 1) ? (Random(0, 1, 1) ? 'True' : True) : (Random(0, 1, 1) ? 'False' : False)
Next
ConsoleWrite(TimerDiff($hTimer) & @CRLF)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

kaotkbliss,

That is what drove the last change to the function and caused this problem - which only occurs when the "start" and "end" strings are the same. My new version solves the dilemma by using a new parameter. ;)

M23

Any chance this will become the new function in Autoit? With it, nothing is lost, only the choice is gained of how you want to use it. I would hate for it to be locked into one way like it is at the moment so that everyone else cannot use the function that comes with autoit in situations like myself.

Link to comment
Share on other sites

  • Moderators

Morthawt,

You will have to wait until the next Beta to see..... :whistle:

But the chances are pretty good that something along these lines will be in there.

;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Morthawt,
 

#2618. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'm always chiming on these types of posts, to play advocate for DOM crawling to grab the necessary data, such as node text, and attributes/values....although, this might not be a DOM, given the node name is surrounded by '"' :).

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...