Jump to content

Recommended Posts

Posted

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?:x

"I'm paper, rock is fine, nerf scissors!!!"

  • Developers
Posted

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

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.
  :)

  • Developers
Posted (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. :x Edited 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.
  :)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...