huldu Posted December 27, 2010 Share Posted December 27, 2010 I was wondering how you compare multiple values in a string? $a = "Test, Test2, Test3, Test4" $b = "Test2" If $a = $b Then ConsoleWrite("True" & @CR) Else ConsoleWrite("False" & @CR) EndIf Of course the above doesnt work, but is there a way to make it work without having to declare a new variable each time? For i am trying to compare a value given with 10 other predefined values. Right now my code looks something like this: IF $a = "Test1" or $a = "Test2" or $a = "Test3" and so on... But there must be a better way to do it? "I'm paper, rock is fine, nerf scissors!!!" Link to comment Share on other sites More sharing options...
Zedna Posted December 27, 2010 Share Posted December 27, 2010 Declare $a as array Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted December 27, 2010 Developers Share Posted December 27, 2010 I have used it this way before: $a = "|Test|Test2|Test3|Test4|" $b = "Test2" If StringInStr($a, "|" & $b & "|") Then ConsoleWrite("True" & @CR) Else ConsoleWrite("False" & @CR) EndIf ThomasBennett 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JohnOne Posted December 27, 2010 Share Posted December 27, 2010 $a = "Test, Test2, Test3, Test4" $b = "Test2" If StringInStr($a,$b) Then ConsoleWrite("True" & @CR) Else ConsoleWrite("False" & @CR) EndIf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 27, 2010 Developers Share Posted December 27, 2010 (edited) $a = "Test, Test2, Test3, Test4" $b = "Test2" If StringInStr($a,$b) Then ConsoleWrite("True" & @CR) Else ConsoleWrite("False" & @CR) EndIf There is a False Positive risk in this way of testing. Edited December 27, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted December 27, 2010 Share Posted December 27, 2010 Dim $a[4] = ["Test", "Test2", "Test3", "Test4"] $b = "Test2" For $i = 0 To UBound($a) - 1 If $a[$i] = $b Then ConsoleWrite("True" & @CR) Else ConsoleWrite("False" & @CR) EndIf Next Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
JohnOne Posted December 27, 2010 Share Posted December 27, 2010 There is a False Positive risk in this way of testing. Something to do with the commas? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
huldu Posted December 27, 2010 Author Share Posted December 27, 2010 Thank you Zedna works like a charm, exactly what i was looking for "I'm paper, rock is fine, nerf scissors!!!" Link to comment Share on other sites More sharing options...
Zedna Posted December 27, 2010 Share Posted December 27, 2010 $a = "Test, Test2, Test3, Test4" $b = "Test2" $a = StringSplit($a, ',') For $i = 1 To $a[0] If StringStripWS($a[$i],3) = $b Then ConsoleWrite("True" & @CR) Else ConsoleWrite("False" & @CR) EndIf Next Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted December 27, 2010 Developers Share Posted December 27, 2010 (edited) Something to do with the commas?no, all to do with delimiting. This would also be true: $b = "st2" or $b = "e"Jos Edited December 27, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JohnOne Posted December 27, 2010 Share Posted December 27, 2010 I see, thanks Jos. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now