Jump to content
Sign in to follow this  
youtuber

Random StringRegExp Question

Recommended Posts

hi

i have find multiple problem :

 - your usage of random seems bad.

 - StringRegExp return a array, so u need use $aYear[0]

#include <Array.au3>; for _ArrayDisplay

$sStart = "yılınız: "
$iRandom = Random(1950, 2050, 1); return 1950-2050 integer
$sString = $sStart & $iRandom

; Return "(.*?)" in a array
$aYear = StringRegExp($sString, '(?i)z:\s(\d+)(.*?)', $STR_REGEXPARRAYGLOBALMATCH)

If @error then
    Msgbox(0, "$iRandom=" & $iRandom, "Year not found")
Else
    Msgbox(0, "$iRandom=" & $iRandom, "Year found : " & $aYear[0])
EndIf

;_ArrayDisplay($aYear); for help to understand

 

Share this post


Link to post
Share on other sites
$test0 = "yılınız: 0"
$test1 = "yılınız: 1"
$testrand = Random(0, 1 , 1)
$testrand = eval("test" & $testrand)
msgbox(0, "Target" , $testrand)

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Use an array :

Local $aTest = ["yılınız: 0", "yılınız: 1"]

$testrand = $aTest[ Random(0, UBound($aTest) - 1 , 1) ]
$year = StringRegExp($testrand, '\d+$', 1)
If @error Then Exit MsgBox(16, "", "invalid string")

MsgBox(0, "", $year[0])

 

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...