Jump to content

[SOLVED] Insert count in the first element on Array


Trong
 Share

Recommended Posts

I know your problem is solved, but maybe you can modify your regex to add a blank value at the first position of your returned array.

Here is the trick :

#Include <Array.au3>

$string = "This is a string with seven words"

$aWords = StringRegExp($string, "(?|^()|(\w+))", 3)
$aWords[0] = UBound($aWords) - 1
_ArrayDisplay($aWords)

You can note the empty group ^() which captures an empty value once. It's the first value of the returned array, so you can set it to UBound($array) - 1

How to add a blank value at the first position ?

Local $sArray = StringRegExp("-(A))-(B))-", "(?si)\Q(\E(.*?)(?=\Q)\E)", 3)
;~ $sArray[0] = UBound($sArray) - 1
If IsArray($sArray) Then
;~  For $i = 1 To $sArray[0]
    For $i = 0 To UBound($sArray) - 1
        ConsoleWrite($sArray[$i] & @CRLF)
    Next
Else
    ConsoleWrite("E: " & @error & " > " & $sArray & @CRLF)
EndIf

 

Regards,
 

Link to comment
Share on other sites

jguinch,
I was just replying to your post #16 about the generic creation of a blank $array[0] using regex  :)

BTW this regex in post #22 is strictly the one used by _StringBetween() , extracted from the include
It could make sense if  \Q...\E  was needed to escape complicated strings - obviously not the case in the example the OP provided

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...