| View previous topic :: View next topic |
| Author |
Message |
Albireo
Joined: 01 Feb 2006 Posts: 62
|
Posted: Fri Aug 08, 2008 7:06 pm Post subject: Check space in variable - How |
|
|
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  |
|
| Back to top |
|
 |
scottmattes
Joined: 21 May 2007 Posts: 98 Location: USA
|
Posted: Fri Aug 08, 2008 7:16 pm Post subject: |
|
|
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 |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Fri Aug 08, 2008 7:37 pm Post subject: |
|
|
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 |
|
 |
Albireo
Joined: 01 Feb 2006 Posts: 62
|
Posted: Fri Aug 08, 2008 7:40 pm Post subject: |
|
|
Thank's it works!  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Fri Aug 08, 2008 8:49 pm Post subject: |
|
|
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 |
|
 |
|