Jump to content
lordsocke

_stringbetween empty string

Recommended Posts

lordsocke

Hey there, 

$string2 = "59?\nHello\nAutoit\nWorld\n",
$string4 = _StringBetween($string2,"\n","\n")
@error
MsgBox(0,"_StringBetween Error",@error)
MsgBox(0,$string4,$string4)
UBound($string4)
@error
MsgBox(0,"Ubound Error",@error)

this is making me a serious headach. It it always delivering me a empty string, and say´s that it finds the string. Any Ideas?

Share this post


Link to post
Share on other sites
VIP
Posted (edited)

GoodLuck with EG on help file:

#include <String.au3>
;~ #include <Array.au3>

Global $Count = 0, $iStringIN = "59?\nHello\nAutoit\nWorld\n"
Global $aArray = _StringBetween($iStringIN, "\n", "\n")
If @error Then
    MsgBox(0, "_StringBetween Error", @error)
Else
    $Count = UBound($aArray)
    For $i = 0 To $Count-1
        ConsoleWrite("-String (" & $i & "): " & $aArray[$i] & @CRLF)
    Next
    MsgBox(0, "_StringBetween Found: " & $Count, "Frist: " & $aArray[0])
;~  _ArrayDisplay($aArray, "Default Search")
EndIf

 

Edited by VIP

Regards,
 

Share this post


Link to post
Share on other sites
lordsocke
5 hours ago, VIP said:

GoodLuck with EG on help file:

#include <String.au3>
;~ #include <Array.au3>

Global $Count = 0, $iStringIN = "59?\nHello\nAutoit\nWorld\n"
Global $aArray = _StringBetween($iStringIN, "\n", "\n")
If @error Then
    MsgBox(0, "_StringBetween Error", @error)
Else
    $Count = UBound($aArray)
    For $i = 0 To $Count-1
        ConsoleWrite("-String (" & $i & "): " & $aArray[$i] & @CRLF)
    Next
    MsgBox(0, "_StringBetween Found: " & $Count, "Frist: " & $aArray[0])
;~  _ArrayDisplay($aArray, "Default Search")
EndIf

 

looks sweet, but it is not fixing the problem... :-(

Share this post


Link to post
Share on other sites
jchd

Yes it is.

Look again at what @VIP pointed: the help file. Read there again and conclude.


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)

Share this post


Link to post
Share on other sites
funkey
Posted (edited)

Maybe this helps with your problem....

#include <Array.au3>

Global $iStringIN = "59?\nHello\nAutoit\nWorld\n"
Global $aArray = _StringBetween2($iStringIN, "\n", "\n", 0)
_ArrayDisplay($aArray, "Default Search")

Func _StringBetween2($s_String, $s_Start, $s_End, $v_Case = 0)
    ;funkey 2018.05.24
    Local $iPos1 = 0, $iPos2
    Local $sRes = ""
    Do
        $iPos1 = StringInStr($s_String, $s_Start, $v_Case, 1, $iPos1 + 1)
        $iPos2 = StringInStr($s_String, $s_End, $v_Case, 1, $iPos1 + StringLen($s_Start))
        If $iPos1 > 0 And $iPos2 > 0 Then $sRes &= StringMid($s_String, $iPos1 + StringLen($s_Start), $iPos2 - $iPos1 - StringLen($s_Start)) & $s_Start
    Until $iPos1 <= 0 Or $iPos2 <= 0

    Local $aRes = StringSplit($sRes, $s_Start, 3)
    If UBound($aRes) > 1 Then
        ReDim $aRes[UBound($aRes) - 1]
    Else
        Return SetError(1, 0, 0)
    EndIf
    Return $aRes
EndFunc   ;==>_StringBetween2

Edit: Added error handling

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
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

×