Jump to content
Sign in to follow this  
brodie28

Just noticed something about the StringIsAlNum func

Recommended Posts

brodie28

All sorts of random symbols get included as being alpha numeric. For instance ß and all sorts of other ones.

Is there a way to just evaluate a string to see if it is a-z 0-9?

Share this post


Link to post
Share on other sites
SmOke_N

All sorts of random symbols get included as being alpha numeric. For instance ß and all sorts of other ones.

Is there a way to just evaluate a string to see if it is a-z 0-9?

StringRegExp($s_text, "(?i)\A[a-z0-9]+\z")

Edit:

In other words:

If StringRegExp($s_text, "(?i)\A[a-z0-9]+\z") Then MsgBox(64, "Info", "String is a to z or 0 to 9")

Edited by SmOke_N
Was only checking for 1 character from begining to end

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
brodie28

thanks. I never could get my heard around regexp...

What would I do to include "-" and "_" in that?

Share this post


Link to post
Share on other sites
SmOke_N

thanks. I never could get my heard around regexp...

What would I do to include "-" and "_" in that?

"(?i)\A[a-z0-9_-]\z"

Edit:

Sorry, I am only checking 1 char there.

It's this:

"(?i)\A[a-z0-9_-]+\z"

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
brodie28

That didn't work.

That only returns strings that are one character long. I want it to return all strings that contain nothing but a-z, 0-9 and _ -

Share this post


Link to post
Share on other sites
SmOke_N

That didn't work.

That only returns strings that are one character long. I want it to return all strings that contain nothing but a-z, 0-9 and _ -

Did you see my edit above :) ?

Anyway... on your other topic, now that I think these two are related... This was half the time:

FileClose(FileOpen("passlist_checked_.txt", 2))
$i_time = TimerInit()

Local $a_array
For $i = 1 To 1
    If FileExists("passlist" & $i & ".txt") Then
        $a_array = StringRegExp(FileRead("passlist" & $i & ".txt"), "(?i)(?:\A|\n)([a-z0-9_-]+)(?:\z|\r)", 3)
        _FileWriteFromArray_Append("passlist_checked_.txt", $a_array, 0)
    EndIf
Next

ConsoleWrite("It took: " & (TimerDiff($i_time) / 1000) & " seconds to finish 1 file." & @CRLF)

Func _FileWriteFromArray_Append($s_file, $a_array, $i_base = 0, $i_ubound = 0)
    If IsArray($a_array) = 0 Then Return SetError(1, 0, 0)
   
    If FileExists($s_file) = 0 Then FileClose(FileOpen($s_file, 2))
   
    If $i_ubound = 0 Or $i_ubound = -1 Or $i_ubound = Default Then $i_ubound = UBound($a_array) - 1
   
    Local $s_write_to_file = FileRead($s_file)
    If $s_write_to_file <> "" Then
        $s_write_to_file = StringRegExpReplace($s_write_to_file, "[\r\n]+\z", "") & @CRLF
    EndIf
   
    For $i = $i_base To $i_ubound
        $s_write_to_file &= $a_array[$i] & @CRLF
    Next
   
    Return FileWrite($s_file, StringTrimRight($s_write_to_file, 2))
EndFunc

And much less code >_< ...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.