AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Check space in variable - How

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Albireo



Joined: 01 Feb 2006
Posts: 62

PostPosted: Fri Aug 08, 2008 7:06 pm    Post subject: Check space in variable - How Reply with quote

Variable tkn contains only one char

I want check if tkn contains space.

Somthing like:

Code:

If tkn = " "
    MsgBox Space is in tkn
else
    MsgBox Tkn = %tkn%

Or

If tkn = Char(32)
    MsgBox Space is in tkn
else
    MsgBox Tkn = %tkn%

Or

If tkn = {Space}
    MsgBox Space is in tkn
else
    MsgBox Tkn = %tkn%




But It doesn't work Crying or Very sad
Back to top
View user's profile Send private message
scottmattes



Joined: 21 May 2007
Posts: 98
Location: USA

PostPosted: Fri Aug 08, 2008 7:16 pm    Post subject: Reply with quote

this works

tkn = " "
Ifinstring, tkn, %a_Space%
MsgBox Space is in tkn
else
MsgBox Tkn = %tkn%
_________________
-------------
Scott Mattes

My small, but growing, collection of scripts.
Back to top
View user's profile Send private message Visit poster's website
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Fri Aug 08, 2008 7:37 pm    Post subject: Reply with quote

You're just using the wrong If-statement syntax:

Code:

If (tkn = " ")
    MsgBox Space is in tkn
else
    MsgBox Tkn = %tkn%

;Or

If (tkn = Char(32))
    MsgBox Space is in tkn
else
    MsgBox Tkn = %tkn%
Back to top
View user's profile Send private message AIM Address
Albireo



Joined: 01 Feb 2006
Posts: 62

PostPosted: Fri Aug 08, 2008 7:40 pm    Post subject: Reply with quote

Thank's it works! Very Happy Very Happy
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Fri Aug 08, 2008 8:49 pm    Post subject: Reply with quote

you mean Chr(32)

also,
Code:

If tkn = %A_Space%
If (tkn = " ")
If (tkn = A_Space)
If (tkn = Chr(32))

are all valid

BTW, are you using tkn to mean token? It is a sign of unmaintainable code to shorten variable names by removing the variables. With modern computers and text editors, there is no good reason to shorten the variables, IMO.

Also, IMO, Notepad is not a modern text editor.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group