Sign in to follow this  
Followers 0
billthecreator

Alternative ways to detect spaces in Inputs, combos, etc.

6 posts in this topic

I have a search bar that doesn't proceed unless it has text.

If $SearchRead<> "" Or StringRegExp($SearchRead, '[:blank:]') = 0 Then

I've tried StringInString, and that doesn't work either.

Am I missing something?

Thanks


[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If $SearchRead And Not StringIsSpace($SearchRead) Then

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi,

although the snippet ripdad posted using StringIsSpace is correct I prefer to use StringStripWS which is a little bit faster, and while we are being overzealous, the snippet can also be used without the "$SearchRead And" part.

If StringStripWS($SearchRead, 8) Then ...

Edit: fixed AutoIt tags

Edited by Robjong

Share this post


Link to post
Share on other sites

Robjong, nice


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi Robjong,

Regarding this snippet:

If StringStripWS($SearchRead, 8) Then ...

What if remaining contents of string ... is the number zero?

--

I don't know if you'd change anything - but this function is my shot at it:

If StringExists('0') Then MsgBox(0, "StringExists('0')", 1)
If StringExists(0) Then MsgBox(0, "StringExists(0)", 1)
;
Func StringExists($s_String, $iChars = 10);<-- number of characters to grab (including WS)
    Return StringLen(StringStripWS(StringLeft($s_String, $iChars), 8))
EndFunc

breakdown:

StringLeft - grabs a small sample to be tested. No need to test all of it.

StringStripWS - (same as intended)

StringLen - mainly determines if a zero exist.

--

thanks and take care!

--EDIT

I gave it some more thought for those that have to KNOW if it's a zero.

Somebody let me know if there's anything you'd change or do different or better. Thanks.

If StringExists('0') Then MsgBox(0, "StringExists('0')", '@extended=' & @extended & ', Return=1')
If StringExists(0) Then MsgBox(0, "StringExists(0)", '@extended=' & @extended & ', Return=1')
;
Func StringExists($s_String, $iChars = 10);<-- number of characters to grab (including WS)
    $s_String = StringStripWS(StringLeft($s_String, $iChars), 8)
    If StringLen($s_String) Then
        If $s_String = 0 Then
            Return SetError(0, 1, 1); string is a 0 - @extended=1, return=1
        Else
            Return SetError(0, 0, 1); is string - @extended=0, return=1
        EndIf
    EndIf
    Return SetError(0, 0, 0); no string - @extended=0, return=0
EndFunc
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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  
Followers 0