Forum Discussion
uni
Altocumulus
Aug 22, 2007Test for characters in a string
I want to test whether any of a set of characters exists within a string. I used the code below, but wonder if anyone can suggest a more efficient (and more elegant) method: string match "*\[XYZ...
Aug 22, 2007
Another option is to use the switch statement. So if you just want to see if "X", "Y", or "Z" are in a string, this would do the trick:
switch -glob $var {
"*A*" -
"*B*" -
"*C*" {
match found
}
default {
no match found
}
}
This will perform a bit faster than a comparable regular expression or if/elseif statements.
-Joe
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects